Advertisement
Guest User

Untitled

a guest
Jun 26th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.43 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<stdint.h>
  4. #include<string.h>
  5. #include<assert.h>
  6. #include<SFmpqapi.h>
  7. #include"expat.h"
  8.  
  9. #pragma pack(push,1)
  10. uint32_t trign;
  11. struct trig{
  12. struct cond{
  13. int32_t l;
  14. int32_t g;
  15. int32_t n;
  16. int16_t u;
  17. int8_t m;
  18. int8_t c;
  19. int8_t r;
  20. int8_t f;
  21. int8_t i[2];
  22. }c[16];
  23. struct act{
  24. int32_t l;
  25. int32_t s;
  26. int32_t w;
  27. int32_t t;
  28. int32_t gf;
  29. int32_t gs;
  30. int16_t u;
  31. int8_t c;
  32. int8_t n;
  33. int8_t f;
  34. int8_t i[3];
  35. }a[64];
  36. int32_t f;
  37. int8_t g[27];
  38. int8_t i;
  39. }trigb[100000];
  40. int condn;
  41. int actn;
  42. struct uprp{
  43. int16_t vf;
  44. int16_t ve;
  45. int8_t p;
  46. int8_t hp;
  47. int8_t sp;
  48. int8_t ep;
  49. int32_t r;
  50. int16_t h;
  51. int16_t f;
  52. int8_t u[4];
  53. };
  54. uint32_t unitn;
  55. struct unit{
  56. int32_t c;
  57. int16_t x;
  58. int16_t y;
  59. int16_t i;
  60. int16_t rt;
  61. struct uprp p;
  62. int32_t cr;
  63. }unitb[2000];
  64. DWORD strs;
  65. uint16_t strn;
  66. uint16_t *stro;
  67. char *strb;
  68. uint8_t mrgni;
  69. uint8_t mrgnn;
  70. struct mrgn{
  71. int32_t x;
  72. int32_t y;
  73. int32_t xe;
  74. int32_t ye;
  75. int16_t s;
  76. int16_t f;
  77. }*mrgnb;
  78. struct uprp *uprpb;
  79. int uprpn;
  80. int8_t *ownrb;
  81. #pragma pack(pop)
  82.  
  83. enum state{
  84. cloaked=1<<0,
  85. burrowed=1<<1,
  86. intransit=1<<2,
  87. hallucinated=1<<3,
  88. invincible=1<<4,
  89. };
  90. enum loc{
  91. low=1<<0,
  92. medium=1<<1,
  93. high=1<<2,
  94. lowair=1<<3,
  95. mediumair=1<<4,
  96. highair=1<<5,
  97. };
  98.  
  99. enum ct{
  100. ct_none,
  101. ct_mint,
  102. ct_trigger,
  103. ct_condition,
  104. ct_action,
  105. ct_condition_type,
  106. ct_condition_l,
  107. ct_condition_g,
  108. ct_condition_n,
  109. ct_condition_u,
  110. ct_condition_m,
  111. ct_condition_r,
  112. ct_action_type,
  113. ct_action_l,
  114. ct_action_s,
  115. ct_action_w,
  116. ct_action_t,
  117. ct_action_gf,
  118. ct_action_gs,
  119. ct_action_u,
  120. ct_action_n,
  121. ct_player,
  122. ct_unitprop,
  123. ct_unitprop_health,
  124. ct_unitprop_shield,
  125. ct_unitprop_energy,
  126. ct_unitprop_resource,
  127. ct_unitprop_hangar,
  128. ct_unitprop_cloaked,
  129. ct_unitprop_burrowed,
  130. ct_unitprop_transit,
  131. ct_unitprop_hallucinated,
  132. ct_unitprop_invincible,
  133. ct_location,
  134. ct_location_x,
  135. ct_location_y,
  136. ct_location_xe,
  137. ct_location_ye,
  138. ct_location_name,
  139. ct_location_low,
  140. ct_location_medium,
  141. ct_location_high,
  142. ct_location_lowair,
  143. ct_location_mediumair,
  144. ct_location_highair,
  145. ct_unit,
  146. ct_unit_type,
  147. ct_unit_player,
  148. ct_unit_x,
  149. ct_unit_y,
  150. ct_unit_health,
  151. ct_unit_shield,
  152. ct_unit_energy,
  153. ct_unit_resource,
  154. ct_unit_hangar,
  155. ct_unit_cloaked,
  156. ct_unit_burrowed,
  157. ct_unit_transit,
  158. ct_unit_hallucinated,
  159. ct_unit_invincible,
  160. };
  161. int context=ct_none;
  162.  
  163. char str_conditions[24][50]={
  164. "No Condition",
  165. "Countdown Timer",
  166. "Command",
  167. "Bring",
  168. "Accumulate",
  169. "Kill",
  170. "Command the Most",
  171. "Command the Most At",
  172. "Most Kills",
  173. "Highest Score",
  174. "Most Resources",
  175. "Switch",
  176. "Elapsed Time",
  177. "Data is a Mission Briefing",
  178. "Opponents",
  179. "Deaths",
  180. "Command the Least",
  181. "Command the Least At",
  182. "Least Kills",
  183. "Lowest Score",
  184. "Least Resources",
  185. "Score",
  186. "Always",
  187. "Never",
  188. };
  189. char str_actions[60][50]={
  190. "No Action",
  191. "Victory",
  192. "Defeat",
  193. "Preserve Trigger",
  194. "Wait",
  195. "Pause Game",
  196. "Unpause Game",
  197. "Transmission",
  198. "Play WAV",
  199. "Display Text Message",
  200. "Center View",
  201. "Create Unit with Properties",
  202. "Set Mission Objectives",
  203. "Set Switch",
  204. "Set Countdown Timer",
  205. "Run AI Script",
  206. "Run AI Script At Location",
  207. "Leaderboard (Control)",
  208. "Leaderboard (Control At Location)",
  209. "Leaderboard (Resources)",
  210. "Leaderboard (Kills)",
  211. "Leaderboard (Points)",
  212. "Kill Unit",
  213. "Kill Unit At Location",
  214. "Remove Unit",
  215. "Remove Unit At Location",
  216. "Set Resources",
  217. "Set Score",
  218. "Minimap Ping",
  219. "Talking Portrait",
  220. "Mute Unit Speech",
  221. "Unmute Unit Speech",
  222. "Leaderboard Computer Players",
  223. "Leaderboard Goal (Control)",
  224. "Leaderboard Goal (Control At Location)",
  225. "Leaderboard Goal (Resources)",
  226. "Leaderboard Goal (Kills)",
  227. "Leaderboard Goal (Points)",
  228. "Move Location",
  229. "Move Unit",
  230. "Leaderboard (Greed)",
  231. "Set Next Scenario",
  232. "Set Doodad State",
  233. "Set Invincibility",
  234. "Create Unit",
  235. "Set Deaths",
  236. "Order",
  237. "Comment",
  238. "Give Units to Player",
  239. "Modify Unit Hit Points",
  240. "Modify Unit Energy",
  241. "Modify Unit Shield Points",
  242. "Modify Unit Resource Amount",
  243. "Modify Unit Hangar Count",
  244. "Pause Timer",
  245. "Unpause Timer",
  246. "Draw",
  247. "Set Alliance Status",
  248. "Disable Debug Mode",
  249. "Enable Debug Mode",
  250. };
  251. char str_groups[27][50]={
  252. "Player 1",
  253. "Player 2",
  254. "Player 3",
  255. "Player 4",
  256. "Player 5",
  257. "Player 6",
  258. "Player 7",
  259. "Player 8",
  260. "Player 9",
  261. "Player 10",
  262. "Player 11",
  263. "Player 12",
  264. "None",
  265. "Current Player",
  266. "Foes",
  267. "Allies",
  268. "Neutral Players",
  269. "All players",
  270. "Force 1",
  271. "Force 2",
  272. "Force 3",
  273. "Force 4",
  274. "Unknown 1",
  275. "Unknown 2",
  276. "Unknown 3",
  277. "Unknown 4",
  278. "Non Allied Victory Players",
  279. };
  280. char str_units[228][50]={
  281. "Terran Marine",
  282. "Terran Ghost",
  283. "Terran Vulture",
  284. "Terran Goliath",
  285. "Goliath Turret",
  286. "Terran Siege Tank (Tank Mode)",
  287. "Tank Turret type 1",
  288. "Terran SCV",
  289. "Terran Wraith",
  290. "Terran Science Vessel",
  291. "Gui Montag (Firebat)",
  292. "Terran Dropship",
  293. "Terran Battlecruiser",
  294. "Vulture Spider Mine",
  295. "Nuclear Missile",
  296. "Terran Civilian",
  297. "Sarah Kerrigan (Ghost)",
  298. "Alan Schezar (Goliath)",
  299. "Alan Turret",
  300. "Jim Raynor (Vulture)",
  301. "Jim Raynor (Marine)",
  302. "Tom Kazansky (Wraith)",
  303. "Magellan (Science Vessel)",
  304. "Edmund Duke (Siege Tank)",
  305. "Duke Turret type 1",
  306. "Edmund Duke (Siege Mode)",
  307. "Duke Turret type 2",
  308. "Arcturus Mengsk (Battlecruiser)",
  309. "Hyperion (Battlecruiser)",
  310. "Norad II (Battlecruiser)",
  311. "Terran Siege Tank (Siege Mode)",
  312. "Tank Turret type 2",
  313. "Terran Firebat",
  314. "Scanner Sweep",
  315. "Terran Medic",
  316. "Zerg Larva",
  317. "Zerg Egg",
  318. "Zerg Zergling",
  319. "Zerg Hydralisk",
  320. "Zerg Ultralisk",
  321. "Zerg Broodling",
  322. "Zerg Drone",
  323. "Zerg Overlord",
  324. "Zerg Mutalisk",
  325. "Zerg Guardian",
  326. "Zerg Queen",
  327. "Zerg Defiler",
  328. "Zerg Scourge",
  329. "Torrasque (Ultralisk)",
  330. "Matriarch (Queen)",
  331. "Infested Terran",
  332. "Infested Kerrigan (Infested Terran)",
  333. "Unclean One (Defiler)",
  334. "Hunter Killer (Hydralisk)",
  335. "Devouring One (Zergling)",
  336. "Kukulza (Mutalisk)",
  337. "Kukulza (Guardian)",
  338. "Yggdrasill (Overlord)",
  339. "Terran Valkyrie",
  340. "Cocoon",
  341. "Protoss Corsair",
  342. "Protoss Dark Templar",
  343. "Zerg Devourer",
  344. "Protoss Dark Archon",
  345. "Protoss Probe",
  346. "Protoss Zealot",
  347. "Protoss Dragoon",
  348. "Protoss High Templar",
  349. "Protoss Archon",
  350. "Protoss Shuttle",
  351. "Protoss Scout",
  352. "Protoss Arbiter",
  353. "Protoss Carrier",
  354. "Protoss Interceptor",
  355. "Dark Templar (Hero)",
  356. "Zeratul (Dark Templar)",
  357. "Tassadar/Zeratul (Archon)",
  358. "Fenix (Zealot)",
  359. "Fenix (Dragoon)",
  360. "Tassadar (Templar)",
  361. "Mojo (Scout)",
  362. "Warbringer (Reaver)",
  363. "Gantrithor (Carrier)",
  364. "Protoss Reaver",
  365. "Protoss Observer",
  366. "Protoss Scarab",
  367. "Danimoth (Arbiter)",
  368. "Aldaris (Templar)",
  369. "Artanis (Scout)",
  370. "Rhynadon (Badlands)",
  371. "Bengalaas (Jungle)",
  372. "Unused type 1",
  373. "Unused type 2",
  374. "Scantid (Desert)",
  375. "Kakaru (Twilight)",
  376. "Ragnasaur (Ash World)",
  377. "Ursadon (Ice World)",
  378. "Zerg Lurker Egg",
  379. "Raszagal (Dark Templar)",
  380. "Samir Duran (Ghost)",
  381. "Alexei Stukov (Ghost)",
  382. "Map Revealer",
  383. "Gerard DuGalle (Ghost)",
  384. "Zerg Lurker",
  385. "Infested Duran",
  386. "Disruption Field",
  387. "Terran Command Center",
  388. "Terran Comsat Station",
  389. "Terran Nuclear Silo",
  390. "Terran Supply Depot",
  391. "Terran Refinery",
  392. "Terran Barracks",
  393. "Terran Academy",
  394. "Terran Factory",
  395. "Terran Starport",
  396. "Terran Control Tower",
  397. "Terran Science Facility",
  398. "Terran Covert Ops",
  399. "Terran Physics Lab",
  400. "Unused Terran Bldg type 1",
  401. "Terran Machine Shop",
  402. "Unused Terran Bldg type 2",
  403. "Terran Engineering Bay",
  404. "Terran Armory",
  405. "Terran Missile Turret",
  406. "Terran Bunker",
  407. "Norad II (Crashed Battlecruiser)",
  408. "Ion Cannon",
  409. "Uraj Crystal",
  410. "Khalis Crystal",
  411. "Infested Command Center",
  412. "Zerg Hatchery",
  413. "Zerg Lair",
  414. "Zerg Hive",
  415. "Zerg Nydus Canal",
  416. "Zerg Hydralisk Den",
  417. "Zerg Defiler Mound",
  418. "Zerg Greater Spire",
  419. "Zerg Queen's Nest",
  420. "Zerg Evolution Chamber",
  421. "Zerg Ultralisk Cavern",
  422. "Zerg Spire",
  423. "Zerg Spawning Pool",
  424. "Zerg Creep Colony",
  425. "Zerg Spore Colony",
  426. "Unused Zerg Bldg",
  427. "Zerg Sunken Colony",
  428. "Zerg Overmind (With Shell)",
  429. "Zerg Overmind",
  430. "Zerg Extractor",
  431. "Mature Crysalis",
  432. "Zerg Cerebrate",
  433. "Zerg Cerebrate Daggoth",
  434. "Unused Zerg Bldg 5",
  435. "Protoss Nexus",
  436. "Protoss Robotics Facility",
  437. "Protoss Pylon",
  438. "Protoss Assimilator",
  439. "Protoss Unused type 1",
  440. "Protoss Observatory",
  441. "Protoss Gateway",
  442. "Protoss Unused type 2",
  443. "Protoss Photon Cannon",
  444. "Protoss Citadel of Adun",
  445. "Protoss Cybernetics Core",
  446. "Protoss Templar Archives",
  447. "Protoss Forge",
  448. "Protoss Stargate",
  449. "Stasis Cell/Prison",
  450. "Protoss Fleet Beacon",
  451. "Protoss Arbiter Tribunal",
  452. "Protoss Robotics Support Bay",
  453. "Protoss Shield Battery",
  454. "Khaydarin Crystal Formation",
  455. "Protoss Temple",
  456. "Xel'Naga Temple",
  457. "Mineral Field (Type 1)",
  458. "Mineral Field (Type 2)",
  459. "Mineral Field (Type 3)",
  460. "Cave",
  461. "Cave-in",
  462. "Cantina",
  463. "Mining Platform",
  464. "Independent Command Center",
  465. "Independent Starport",
  466. "Jump Gate",
  467. "Ruins",
  468. "Kyadarin Crystal Formation",
  469. "Vespene Geyser",
  470. "Warp Gate",
  471. "Psi Disrupter",
  472. "Zerg Marker",
  473. "Terran Marker",
  474. "Protoss Marker",
  475. "Zerg Beacon",
  476. "Terran Beacon",
  477. "Protoss Beacon",
  478. "Zerg Flag Beacon",
  479. "Terran Flag Beacon",
  480. "Protoss Flag Beacon",
  481. "Power Generator",
  482. "Overmind Cocoon",
  483. "Dark Swarm",
  484. "Floor Missile Trap",
  485. "Floor Hatch (UNUSED)",
  486. "Left Upper Level Door",
  487. "Right Upper Level Door",
  488. "Left Pit Door",
  489. "Right Pit Door",
  490. "Floor Gun Trap",
  491. "Left Wall Missile Trap",
  492. "Left Wall Flame Trap",
  493. "Right Wall Missile Trap",
  494. "Right Wall Flame Trap",
  495. "Start Location",
  496. "Flag",
  497. "Young Chrysalis",
  498. "Psi Emitter",
  499. "Data Disc",
  500. "Khaydarin Crystal",
  501. "Mineral Chunk (Type 1)",
  502. "Mineral Chunk (Type 2)",
  503. "Vespene Orb (Protoss Type 1)",
  504. "Vespene Orb (Protoss Type 2)",
  505. "Vespene Sac (Zerg Type 1)",
  506. "Vespene Sac (Zerg Type 2)",
  507. "Vespene Tank (Terran Type 1)",
  508. "Vespene Tank (Terran Type 2)",
  509. };
  510. char str_mod[12][50]={
  511. "At least",
  512. "At most",
  513. "is set",
  514. "not set",
  515. "set",
  516. "clear",
  517. "toggle",
  518. "Set To",
  519. "Add",
  520. "Subtract",
  521. "Exactly",
  522. "randomize",
  523. };
  524. char str_res[3][50]={
  525. "ore",
  526. "gas",
  527. "ore and gas",
  528. };
  529. char str_ally[3][50]={
  530. "Enemy",
  531. "Ally",
  532. "Allied Victory",
  533. };
  534. char str_order[3][50]={
  535. "Move",
  536. "Patrol",
  537. "Attack",
  538. };
  539. char str_score[8][50]={
  540. "Total",
  541. "Units",
  542. "Buildings",
  543. "Units and Buildings",
  544. "Kills",
  545. "Razings",
  546. "Kills and Razings",
  547. "Custom",
  548. };
  549.  
  550. int16_t str(const char *s){
  551. int16_t i=0;
  552. while(i<strn){
  553. if(!strcmp(strb-2-2*strn+stro[i],s))return(i+1);
  554. i++;
  555. }
  556. i=1;
  557. while(i<strn){
  558. if(!strlen(strb-2-2*strn+stro[i])){
  559. stro[i]=2+2*strn+strs;
  560. strb=(char *)realloc(strb,strs+strlen(s)+1);
  561. strcpy(strb+strs,s);
  562. strs+=strlen(s)+1;
  563. return(i+1);
  564. }
  565. i++;
  566. }
  567. puts("Exceeded string limit.");
  568. exit(EXIT_FAILURE);
  569. }
  570.  
  571. uint8_t mrgn(int32_t x,int32_t y,int32_t xe,int32_t ye,int16_t f){
  572. if(mrgni==mrgnn){
  573. puts("Exceeded location limit.");
  574. exit(EXIT_FAILURE);
  575. }
  576. while((mrgnb+mrgni)->s){
  577. mrgni++;
  578. if(mrgni==mrgnn){
  579. puts("Exceeded location limit.");
  580. exit(EXIT_FAILURE);
  581. }
  582. }
  583. (mrgnb+mrgni)->x=x;
  584. (mrgnb+mrgni)->y=y;
  585. (mrgnb+mrgni)->xe=xe;
  586. (mrgnb+mrgni)->ye=ye;
  587. (mrgnb+mrgni)->f=f;
  588. return(++mrgni);
  589. }
  590. uint8_t mrgns(int16_t s){
  591. uint8_t i=0;
  592. while((mrgnb+i)->s!=s){
  593. i++;
  594. if(i==mrgnn){
  595. printf("Invalid location string: %s\n",strb-2-2*strn+stro[s-1]);
  596. exit(EXIT_FAILURE);
  597. }
  598. }
  599. return(i+1);
  600. }
  601.  
  602. void XMLCALL
  603. startElement(void *userData,const XML_Char *name,const XML_Char **attr){
  604. if(context==ct_none){
  605. if(!strcmp(name,"mint")){
  606. context=ct_mint;
  607. }
  608. }else if(context==ct_mint){
  609. if(!strcmp(name,"trigger")){
  610. // trigb=(struct trig *)realloc(trigb,sizeof(struct trig)*(trign+1));
  611. // memset(trigb+trign,0,sizeof(struct trig));
  612. condn=0;
  613. actn=0;
  614. context=ct_trigger;
  615. }else if(!strcmp(name,"unitprop")){
  616. struct uprp *u=&uprpb[uprpn];
  617. u->vf=-1;
  618. u->ve=-1;
  619. context=ct_unitprop;
  620. }else if(!strcmp(name,"location")){
  621. mrgn(0,0,0,0,0);
  622. context=ct_location;
  623. }else if(!strcmp(name,"unit")){
  624. // unitb=(struct unit *)realloc(unitb,sizeof(struct unit)*(unitn+1));
  625. // memset(unitb+unitn,0,sizeof(struct unit));
  626. struct unit *unit=unitb+unitn;
  627. unit->p.vf=-1;
  628. unit->p.ve=-1;
  629. context=ct_unit;
  630. }
  631. }else if(context==ct_trigger){
  632. if(!strcmp(name,"condition")){
  633. if(condn==16){
  634. puts("Exceeded condition limit.");
  635. exit(EXIT_FAILURE);
  636. }
  637. context=ct_condition;
  638. }else if(!strcmp(name,"action")){
  639. if(actn==64){
  640. puts("Exceeded action limit.");
  641. exit(EXIT_FAILURE);
  642. }
  643. context=ct_action;
  644. }else if(!strcmp(name,"player")){
  645. context=ct_player;
  646. }else if(!strcmp(name,"ptf")){
  647. (trigb+trign)->f|=1<<2;
  648. }
  649. }else if(context==ct_condition){
  650. if(!strcmp(name,"type")){
  651. context=ct_condition_type;
  652. }else if(!strcmp(name,"l")){
  653. context=ct_condition_l;
  654. }else if(!strcmp(name,"g")){
  655. context=ct_condition_g;
  656. }else if(!strcmp(name,"n")){
  657. context=ct_condition_n;
  658. }else if(!strcmp(name,"u")){
  659. context=ct_condition_u;
  660. }else if(!strcmp(name,"m")){
  661. context=ct_condition_m;
  662. }else if(!strcmp(name,"r")){
  663. context=ct_condition_r;
  664. }
  665. }else if(context==ct_action){
  666. if(!strcmp(name,"type")){
  667. context=ct_action_type;
  668. }else if(!strcmp(name,"l")){
  669. context=ct_action_l;
  670. }else if(!strcmp(name,"s")){
  671. context=ct_action_s;
  672. }else if(!strcmp(name,"w")){
  673. context=ct_action_w;
  674. }else if(!strcmp(name,"t")){
  675. context=ct_action_t;
  676. }else if(!strcmp(name,"gf")){
  677. context=ct_action_gf;
  678. }else if(!strcmp(name,"gs")){
  679. context=ct_action_gs;
  680. }else if(!strcmp(name,"u")){
  681. context=ct_action_u;
  682. }else if(!strcmp(name,"n")){
  683. context=ct_action_n;
  684. }else if(!strcmp(name,"adf")){
  685. struct trig::act *act=&(trigb+trign)->a[actn];
  686. act->f|=1<<2;
  687. }
  688. }else if(context==ct_unitprop){
  689. struct uprp *u=&uprpb[uprpn];
  690. if(!strcmp(name,"health")){
  691. context=ct_unitprop_health;
  692. }else if(!strcmp(name,"shield")){
  693. context=ct_unitprop_shield;
  694. }else if(!strcmp(name,"energy")){
  695. context=ct_unitprop_energy;
  696. }else if(!strcmp(name,"resource")){
  697. context=ct_unitprop_resource;
  698. }else if(!strcmp(name,"hangar")){
  699. context=ct_unitprop_hangar;
  700. }else if(!strcmp(name,"cloaked")){
  701. u->f|=cloaked;
  702. context=ct_unitprop_cloaked;
  703. }else if(!strcmp(name,"burrowed")){
  704. u->f|=burrowed;
  705. context=ct_unitprop_burrowed;
  706. }else if(!strcmp(name,"transit")){
  707. u->f|=intransit;
  708. context=ct_unitprop_transit;
  709. }else if(!strcmp(name,"hallucinated")){
  710. u->f|=hallucinated;
  711. context=ct_unitprop_hallucinated;
  712. }else if(!strcmp(name,"invincible")){
  713. u->f|=invincible;
  714. context=ct_unitprop_invincible;
  715. }
  716. }else if(context==ct_location){
  717. struct mrgn *m=&mrgnb[mrgni-1];
  718. if(!strcmp(name,"x")){
  719. context=ct_location_x;
  720. }else if(!strcmp(name,"y")){
  721. context=ct_location_y;
  722. }else if(!strcmp(name,"xe")){
  723. context=ct_location_xe;
  724. }else if(!strcmp(name,"ye")){
  725. context=ct_location_ye;
  726. }else if(!strcmp(name,"name")){
  727. context=ct_location_name;
  728. }else if(!strcmp(name,"low")){
  729. m->f|=low;
  730. context=ct_location_low;
  731. }else if(!strcmp(name,"medium")){
  732. m->f|=medium;
  733. context=ct_location_medium;
  734. }else if(!strcmp(name,"high")){
  735. m->f|=high;
  736. context=ct_location_high;
  737. }else if(!strcmp(name,"lowair")){
  738. m->f|=lowair;
  739. context=ct_location_lowair;
  740. }else if(!strcmp(name,"mediumair")){
  741. m->f|=mediumair;
  742. context=ct_location_mediumair;
  743. }else if(!strcmp(name,"highair")){
  744. m->f|=highair;
  745. context=ct_location_highair;
  746. }
  747. }else if(context==ct_unit){
  748. struct unit *unit=&unitb[unitn];
  749. if(!strcmp(name,"type")){
  750. context=ct_unit_type;
  751. }else if(!strcmp(name,"player")){
  752. context=ct_unit_player;
  753. }else if(!strcmp(name,"x")){
  754. context=ct_unit_x;
  755. }else if(!strcmp(name,"y")){
  756. context=ct_unit_y;
  757. }else if(!strcmp(name,"health")){
  758. context=ct_unit_health;
  759. }else if(!strcmp(name,"shield")){
  760. context=ct_unit_shield;
  761. }else if(!strcmp(name,"energy")){
  762. context=ct_unit_energy;
  763. }else if(!strcmp(name,"resource")){
  764. context=ct_unit_resource;
  765. }else if(!strcmp(name,"hangar")){
  766. context=ct_unit_hangar;
  767. }else if(!strcmp(name,"cloaked")){
  768. unit->p.f|=cloaked;
  769. context=ct_unit_cloaked;
  770. }else if(!strcmp(name,"burrowed")){
  771. unit->p.f|=burrowed;
  772. context=ct_unit_burrowed;
  773. }else if(!strcmp(name,"transit")){
  774. unit->p.f|=intransit;
  775. context=ct_unit_transit;
  776. }else if(!strcmp(name,"hallucinated")){
  777. unit->p.f|=hallucinated;
  778. context=ct_unit_hallucinated;
  779. }else if(!strcmp(name,"invincible")){
  780. unit->p.f|=invincible;
  781. context=ct_unit_invincible;
  782. }
  783. }
  784. }
  785. void XMLCALL
  786. endElement(void *userData,const XML_Char *name){
  787. if(context==ct_mint){
  788. if(!strcmp(name,"mint")){
  789. context=ct_none;
  790. }
  791. }else if(context==ct_trigger){
  792. if(!strcmp(name,"trigger")){
  793. trign++;
  794. context=ct_mint;
  795. }
  796. }else if(context==ct_condition){
  797. if(!strcmp(name,"condition")){
  798. condn++;
  799. context=ct_trigger;
  800. }
  801. }else if(context==ct_action){
  802. if(!strcmp(name,"action")){
  803. actn++;
  804. context=ct_trigger;
  805. }
  806. }else if(context==ct_player){
  807. if(!strcmp(name,"player")){
  808. context=ct_trigger;
  809. }
  810. }else if(context==ct_condition_type||
  811. context==ct_condition_l||
  812. context==ct_condition_g||
  813. context==ct_condition_n||
  814. context==ct_condition_u||
  815. context==ct_condition_m||
  816. context==ct_condition_r){
  817. context=ct_condition;
  818. }else if(context==ct_action_type||
  819. context==ct_action_l||
  820. context==ct_action_s||
  821. context==ct_action_w||
  822. context==ct_action_t||
  823. context==ct_action_gf||
  824. context==ct_action_gs||
  825. context==ct_action_u||
  826. context==ct_action_n){
  827. context=ct_action;
  828. }else if(context==ct_unitprop){
  829. uprpn++;
  830. context=ct_mint;
  831. }else if(context==ct_unitprop_health||
  832. context==ct_unitprop_shield||
  833. context==ct_unitprop_energy||
  834. context==ct_unitprop_resource||
  835. context==ct_unitprop_hangar||
  836. context==ct_unitprop_cloaked||
  837. context==ct_unitprop_burrowed||
  838. context==ct_unitprop_transit||
  839. context==ct_unitprop_hallucinated||
  840. context==ct_unitprop_invincible){
  841. context=ct_unitprop;
  842. }else if(context==ct_location){
  843. context=ct_mint;
  844. }else if(context==ct_location_x||
  845. context==ct_location_y||
  846. context==ct_location_xe||
  847. context==ct_location_ye||
  848. context==ct_location_name||
  849. context==ct_location_low||
  850. context==ct_location_medium||
  851. context==ct_location_high||
  852. context==ct_location_lowair||
  853. context==ct_location_mediumair||
  854. context==ct_location_highair){
  855. context=ct_location;
  856. }else if(context==ct_unit){
  857. unitn++;
  858. context=ct_mint;
  859. }else if(context==ct_unit_type||
  860. context==ct_unit_player||
  861. context==ct_unit_x||
  862. context==ct_unit_y||
  863. context==ct_unit_health||
  864. context==ct_unit_shield||
  865. context==ct_unit_energy||
  866. context==ct_unit_resource||
  867. context==ct_unit_hangar||
  868. context==ct_unit_cloaked||
  869. context==ct_unit_burrowed||
  870. context==ct_unit_transit||
  871. context==ct_unit_hallucinated||
  872. context==ct_unit_invincible){
  873. context=ct_unit;
  874. }
  875. }
  876. void XMLCALL
  877. charData(void *userData,const XML_Char *string,int len){
  878. char s[len+1];
  879. memcpy(s,string,len);
  880. s[len]=0;
  881. struct trig::cond *cond=&(trigb+trign)->c[condn];
  882. struct trig::act *act=&(trigb+trign)->a[actn];
  883. struct uprp *u=&uprpb[uprpn];
  884. struct mrgn *m=&mrgnb[mrgni-1];
  885. struct unit *unit=&unitb[unitn];
  886. if(context==ct_condition_type){
  887. int i=0;
  888. while(i<24){
  889. if(!strcmp(s,str_conditions[i]))break;
  890. i++;
  891. }
  892. if(i==24){
  893. printf("Invalid condition type: %s\n",s);
  894. exit(EXIT_FAILURE);
  895. }
  896. cond->c=i;
  897. }else if(context==ct_condition_l){
  898. cond->l=mrgns(str(s));
  899. }else if(context==ct_condition_g){
  900. int i=0;
  901. while(i<27){
  902. if(!strcmp(s,str_groups[i]))break;
  903. i++;
  904. }
  905. if(i==27){
  906. char *se;
  907. i=strtoll(s,&se,0);
  908. if(se==s){
  909. printf("Invalid condition g: %s\n",s);
  910. exit(EXIT_FAILURE);
  911. }
  912. }
  913. cond->g=i;
  914. }else if(context==ct_condition_n){
  915. char *se;
  916. uint32_t i=strtoll(s,&se,0);
  917. cond->n=i;
  918. if(se==s){
  919. printf("Invalid condition n: %s\n",s);
  920. exit(EXIT_FAILURE);
  921. }
  922. }else if(context==ct_condition_u){
  923. int i=0;
  924. while(i<228){
  925. if(!strcmp(s,str_units[i]))break;
  926. i++;
  927. }
  928. if(i==228){
  929. char *se;
  930. i=strtoll(s,&se,0);
  931. if(se==s){
  932. printf("Invalid condition u: %s\n",s);
  933. exit(EXIT_FAILURE);
  934. }
  935. }
  936. cond->u=i;
  937. }else if(context==ct_condition_m){
  938. int i=0;
  939. while(i<12){
  940. if(!strcmp(s,str_mod[i]))break;
  941. i++;
  942. }
  943. if(i==12){
  944. printf("Invalid condition m: %s\n",s);
  945. exit(EXIT_FAILURE);
  946. }
  947. cond->m=i;
  948. }else if(context==ct_condition_r){
  949. int i=0;
  950. while(i<3){
  951. if(!strcmp(s,str_res[i]))break;
  952. i++;
  953. }
  954. if(i==3){
  955. i=0;
  956. while(i<8){
  957. if(!strcmp(s,str_score[i]))break;
  958. i++;
  959. }
  960. if(i==8){
  961. char *se;
  962. i=strtoll(s,&se,0);
  963. if(se==s){
  964. printf("Invalid condition r: %s\n",s);
  965. exit(EXIT_FAILURE);
  966. }
  967. }
  968. }
  969. cond->r=i;
  970. }else if(context==ct_action_type){
  971. int i=0;
  972. while(i<60){
  973. if(!strcmp(s,str_actions[i]))break;
  974. i++;
  975. }
  976. if(i==60){
  977. printf("Invalid action type: %s\n",s);
  978. exit(EXIT_FAILURE);
  979. }
  980. act->c=i;
  981. }else if(context==ct_action_l){
  982. act->l=mrgns(str(s));
  983. }else if(context==ct_action_s){
  984. act->s=str(s);
  985. }else if(context==ct_action_w){
  986. act->w=str(s);
  987. }else if(context==ct_action_t){
  988. char *se;
  989. act->t=strtoll(s,&se,0);
  990. if(se==s){
  991. printf("Invalid action t: %s\n",s);
  992. exit(EXIT_FAILURE);
  993. }
  994. }else if(context==ct_action_gf){
  995. int i=0;
  996. while(i<27){
  997. if(!strcmp(s,str_groups[i]))break;
  998. i++;
  999. }
  1000. if(i==27){
  1001. printf("Invalid action gf: %s\n",s);
  1002. exit(EXIT_FAILURE);
  1003. }
  1004. act->gf=i;
  1005. }else if(context==ct_action_gs){
  1006. uint32_t i=0;
  1007. if(act->c==15||act->c==16){ //Run AI Script{, At Location}
  1008. i=*(int32_t *)s;
  1009. }else if(act->c==38||act->c==39||act->c==46){ //Move {Location,Unit}, Order
  1010. i=mrgns(str(s));
  1011. }else{
  1012. while(i<27){
  1013. if(!strcmp(s,str_groups[i]))break;
  1014. i++;
  1015. }
  1016. if(i==27){
  1017. char *se;
  1018. i=strtoll(s,&se,0);
  1019. if(se==s){
  1020. printf("Invalid action gs: %s\n",s);
  1021. exit(EXIT_FAILURE);
  1022. }
  1023. }
  1024. }
  1025. act->gs=i;
  1026. }else if(context==ct_action_u){
  1027. uint16_t i=0;
  1028. while(i<3){
  1029. if(!strcmp(s,str_res[i]))break;
  1030. i++;
  1031. }
  1032. if(i==3){
  1033. i=0;
  1034. while(i<8){
  1035. if(!strcmp(s,str_score[i]))break;
  1036. i++;
  1037. }
  1038. if(i==8){
  1039. i=0;
  1040. while(i<3){
  1041. if(!strcmp(s,str_ally[i]))break;
  1042. i++;
  1043. }
  1044. if(i==3){
  1045. i=0;
  1046. while(i<228){
  1047. if(!strcmp(s,str_units[i]))break;
  1048. i++;
  1049. }
  1050. if(i==228){
  1051. printf("Invalid action u: %s\n",s);
  1052. exit(EXIT_FAILURE);
  1053. }
  1054. }
  1055. }
  1056. }
  1057. act->u=i;
  1058. }else if(context==ct_action_n){
  1059. int i=0;
  1060. while(i<12){
  1061. if(!strcmp(s,str_mod[i]))break;
  1062. i++;
  1063. }
  1064. if(i==12){
  1065. i=0;
  1066. while(i<3){
  1067. if(!strcmp(s,str_order[i]))break;
  1068. i++;
  1069. }
  1070. if(i==3){
  1071. char *se;
  1072. i=strtoll(s,&se,0);
  1073. if(se==s){
  1074. printf("Invalid action n: %s\n",s);
  1075. exit(EXIT_FAILURE);
  1076. }
  1077. }
  1078. }
  1079. act->n=i;
  1080. }else if(context==ct_player){
  1081. int i=0;
  1082. while(i<27){
  1083. if(!strcmp(s,str_groups[i]))break;
  1084. i++;
  1085. }
  1086. if(i==27){
  1087. printf("Invalid player: %s\n",s);
  1088. exit(EXIT_FAILURE);
  1089. }
  1090. (trigb+trign)->g[i]=1;
  1091. }else if(context==ct_unitprop_health){
  1092. char *se;
  1093. u->hp=strtoll(s,&se,0);
  1094. if(se==s){
  1095. printf("Invalid unitprop health: %s\n",s);
  1096. exit(EXIT_FAILURE);
  1097. }
  1098. }else if(context==ct_unitprop_shield){
  1099. char *se;
  1100. u->sp=strtoll(s,&se,0);
  1101. if(se==s){
  1102. printf("Invalid unitprop shield: %s\n",s);
  1103. exit(EXIT_FAILURE);
  1104. }
  1105. }else if(context==ct_unitprop_energy){
  1106. char *se;
  1107. u->ep=strtoll(s,&se,0);
  1108. if(se==s){
  1109. printf("Invalid unitprop energy: %s\n",s);
  1110. exit(EXIT_FAILURE);
  1111. }
  1112. }else if(context==ct_unitprop_resource){
  1113. char *se;
  1114. u->r=strtoll(s,&se,0);
  1115. if(se==s){
  1116. printf("Invalid unitprop resource: %s\n",s);
  1117. exit(EXIT_FAILURE);
  1118. }
  1119. }else if(context==ct_unitprop_hangar){
  1120. char *se;
  1121. u->h=strtoll(s,&se,0);
  1122. if(se==s){
  1123. printf("Invalid unitprop hangar: %s\n",s);
  1124. exit(EXIT_FAILURE);
  1125. }
  1126. }else if(context==ct_location_x){
  1127. char *se;
  1128. m->x=strtoll(s,&se,0);
  1129. if(se==s){
  1130. printf("Invalid location x: %s\n",s);
  1131. exit(EXIT_FAILURE);
  1132. }
  1133. }else if(context==ct_location_y){
  1134. char *se;
  1135. m->y=strtoll(s,&se,0);
  1136. if(se==s){
  1137. printf("Invalid location y: %s\n",s);
  1138. exit(EXIT_FAILURE);
  1139. }
  1140. }else if(context==ct_location_xe){
  1141. char *se;
  1142. m->xe=strtoll(s,&se,0);
  1143. if(se==s){
  1144. printf("Invalid location xe: %s\n",s);
  1145. exit(EXIT_FAILURE);
  1146. }
  1147. }else if(context==ct_location_ye){
  1148. char *se;
  1149. m->ye=strtoll(s,&se,0);
  1150. if(se==s){
  1151. printf("Invalid location ye: %s\n",s);
  1152. exit(EXIT_FAILURE);
  1153. }
  1154. }else if(context==ct_location_name){
  1155. m->s=str(s);
  1156. }else if(context==ct_unit_type){
  1157. int i=0;
  1158. while(i<228){
  1159. if(!strcmp(str_units[i],s))break;
  1160. i++;
  1161. }
  1162. if(i==228){
  1163. char *se;
  1164. i=strtoll(s,&se,0);
  1165. if(se==s){
  1166. printf("Invalid unit type: %s\n",s);
  1167. exit(EXIT_FAILURE);
  1168. }
  1169. }
  1170. unit->i=i;
  1171. }else if(context==ct_unit_player){
  1172. int i=0;
  1173. while(i<27){
  1174. if(!strcmp(str_groups[i],s))break;
  1175. i++;
  1176. }
  1177. if(i==27){
  1178. char *se;
  1179. i=strtoll(s,&se,0);
  1180. if(se==s){
  1181. printf("Invalid unit player: %s\n",s);
  1182. exit(EXIT_FAILURE);
  1183. }
  1184. }
  1185. unit->p.p=i;
  1186. }else if(context==ct_unit_x){
  1187. char *se;
  1188. unit->x=strtoll(s,&se,0);
  1189. if(se==s){
  1190. printf("Invalid unit x: %s\n",s);
  1191. exit(EXIT_FAILURE);
  1192. }
  1193. }else if(context==ct_unit_y){
  1194. char *se;
  1195. unit->y=strtoll(s,&se,0);
  1196. if(se==s){
  1197. printf("Invalid unit y: %s\n",s);
  1198. exit(EXIT_FAILURE);
  1199. }
  1200. }else if(context==ct_unit_health){
  1201. char *se;
  1202. unit->p.hp=strtoll(s,&se,0);
  1203. if(se==s){
  1204. printf("Invalid unit health: %s\n",s);
  1205. exit(EXIT_FAILURE);
  1206. }
  1207. }else if(context==ct_unit_shield){
  1208. char *se;
  1209. unit->p.sp=strtoll(s,&se,0);
  1210. if(se==s){
  1211. printf("Invalid unit shield: %s\n",s);
  1212. exit(EXIT_FAILURE);
  1213. }
  1214. }else if(context==ct_unit_energy){
  1215. char *se;
  1216. unit->p.ep=strtoll(s,&se,0);
  1217. if(se==s){
  1218. printf("Invalid unit energy: %s\n",s);
  1219. exit(EXIT_FAILURE);
  1220. }
  1221. }else if(context==ct_unit_resource){
  1222. char *se;
  1223. unit->p.r=strtoll(s,&se,0);
  1224. if(se==s){
  1225. printf("Invalid unit resource: %s\n",s);
  1226. exit(EXIT_FAILURE);
  1227. }
  1228. }else if(context==ct_unit_hangar){
  1229. char *se;
  1230. unit->p.h=strtoll(s,&se,0);
  1231. if(se==s){
  1232. printf("Invalid unit hangar: %s\n",s);
  1233. exit(EXIT_FAILURE);
  1234. }
  1235. }
  1236. }
  1237.  
  1238. int
  1239. main(int ac,char **av){
  1240. if(ac!=4){
  1241. puts("Inappropriate arguments");
  1242. exit(EXIT_FAILURE);
  1243. }
  1244.  
  1245. MPQHANDLE mpq;
  1246. assert(SFileOpenArchive(av[1],0,0,&mpq));
  1247. MPQHANDLE scen;
  1248. assert(SFileOpenFileEx(mpq,"staredit\\scenario.chk",0,&scen));
  1249. DWORD size=SFileGetFileSize(scen,NULL);
  1250. char *buf=(char *)malloc(size);
  1251. DWORD read;
  1252. SFileReadFile(scen,buf,size,&read,NULL);
  1253. assert(read==size);
  1254. SFileCloseFile(scen);
  1255. SFileCloseArchive(mpq);
  1256.  
  1257. DWORD off=0;
  1258. while(off<size){
  1259. DWORD chk=8+*(DWORD *)(buf+off+4);
  1260. if(*(DWORD *)(buf+off)==*(DWORD *)"TRIG"){
  1261. trign=(-8+chk)/sizeof(struct trig);
  1262. // trigb=(struct trig *)malloc(-8+chk);
  1263. memcpy(trigb,buf+off+8,-8+chk);
  1264. memmove(buf+off,buf+off+chk,-off-chk+size);
  1265. size-=chk;
  1266. }else if(*(DWORD *)(buf+off)==*(DWORD *)"UNIT"){
  1267. unitn=(-8+chk)/sizeof(struct unit);
  1268. // unitb=(struct unit *)malloc(-8+chk);
  1269. memcpy(unitb,buf+off+8,-8+chk);
  1270. memmove(buf+off,buf+off+chk,-off-chk+size);
  1271. size-=chk;
  1272. }else if(*(DWORD *)(buf+off)==*(DWORD *)"STR "){
  1273. strn=*(uint16_t *)(buf+off+8);
  1274. stro=(uint16_t *)malloc(2*strn);
  1275. memcpy(stro,buf+off+8+2,2*strn);
  1276. strs=-8-2-2*strn+chk;
  1277. strb=(char *)malloc(strs);
  1278. memcpy(strb,buf+off+8+2+2*strn,strs);
  1279. memmove(buf+off,buf+off+chk,-off-chk+size);
  1280. size-=chk;
  1281. }else if(*(DWORD *)(buf+off)==*(DWORD *)"MRGN"){
  1282. mrgnn=(-8+chk)/sizeof(struct mrgn);
  1283. mrgnb=(struct mrgn *)(buf+off+8);
  1284. off+=chk;
  1285. }else if(*(DWORD *)(buf+off)==*(DWORD *)"UPRP"){
  1286. uprpb=(struct uprp *)(buf+off+8);
  1287. off+=chk;
  1288. }else if(*(DWORD *)(buf+off)==*(DWORD *)"OWNR"){
  1289. ownrb=(int8_t *)(buf+off+8);
  1290. off+=chk;
  1291. }else{
  1292. off+=chk;
  1293. }
  1294. }
  1295.  
  1296. XML_Parser parser=XML_ParserCreate(NULL);
  1297. XML_SetElementHandler(parser,startElement,endElement);
  1298. XML_SetCharacterDataHandler(parser,charData);
  1299. FILE *xml=fopen(av[2],"rb");
  1300. fseek(xml,0,SEEK_END);
  1301. long xmlSize=ftell(xml);
  1302. rewind(xml);
  1303. char *xmlbuf=(char *)malloc(xmlSize);
  1304. int len=fread(xmlbuf,1,xmlSize,xml);
  1305. XML_Parse(parser,xmlbuf,len,1);
  1306. XML_ParserFree(parser);
  1307.  
  1308. int mrgnc=0;
  1309. for(int i=0;i<mrgnn;i++){
  1310. if((mrgnb+i)->s){
  1311. mrgnc++;
  1312. }
  1313. }
  1314.  
  1315. DWORD sizeo=size+(8+sizeof(struct unit)*unitn)
  1316. +(8+sizeof(struct trig)*trign)
  1317. +(8+2+2*strn+strs);
  1318. char *bufo=(char *)malloc(sizeo);
  1319. char *bufoa=bufo;
  1320.  
  1321. memcpy(bufoa,buf,size);
  1322. free(buf);
  1323. bufoa+=size;
  1324.  
  1325. memcpy(bufoa,"UNIT",4);
  1326. bufoa+=4;
  1327. unitn*=sizeof(struct unit);
  1328. memcpy(bufoa,&unitn,4);
  1329. bufoa+=4;
  1330. memcpy(bufoa,unitb,unitn);
  1331. // free(unitb);
  1332. bufoa+=unitn;
  1333.  
  1334. memcpy(bufoa,"TRIG",4);
  1335. bufoa+=4;
  1336. trign*=sizeof(struct trig);
  1337. memcpy(bufoa,&trign,4);
  1338. bufoa+=4;
  1339. memcpy(bufoa,trigb,trign);
  1340. // free(trigb);
  1341. bufoa+=trign;
  1342.  
  1343. memcpy(bufoa,"STR ",4);
  1344. bufoa+=4;
  1345. DWORD chk=2+2*strn+strs;
  1346. memcpy(bufoa,&chk,4);
  1347. bufoa+=4;
  1348. memcpy(bufoa,&strn,2);
  1349. bufoa+=2;
  1350. memcpy(bufoa,stro,2*strn);
  1351. free(stro);
  1352. bufoa+=2*strn;
  1353. memcpy(bufoa,strb,strs);
  1354. free(strb);
  1355. bufoa+=strs;
  1356.  
  1357. MPQHANDLE mpqo;
  1358. assert(mpqo=MpqOpenArchiveForUpdate(av[3],MOAU_CREATE_ALWAYS|MOAU_MAINTAIN_LISTFILE,2));
  1359. assert(MpqAddFileFromBuffer(mpqo,(void *)bufo,sizeo,"staredit\\scenario.chk",MAFA_COMPRESS));
  1360. free(bufo);
  1361. MpqCloseUpdatedArchive(mpqo,0);
  1362.  
  1363. printf("Trigger count: %d\n",trign/sizeof(struct trig));
  1364. printf("Unit count: %d\n",unitn/sizeof(struct unit));
  1365. printf("Location count: %d\n",mrgnc);
  1366.  
  1367. exit(EXIT_SUCCESS);
  1368. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement