Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<stdio.h>
- #include<stdint.h>
- #include<string.h>
- #include<assert.h>
- #include<SFmpqapi.h>
- #include"expat.h"
- #pragma pack(push,1)
- uint32_t trign;
- struct trig{
- struct cond{
- int32_t l;
- int32_t g;
- int32_t n;
- int16_t u;
- int8_t m;
- int8_t c;
- int8_t r;
- int8_t f;
- int8_t i[2];
- }c[16];
- struct act{
- int32_t l;
- int32_t s;
- int32_t w;
- int32_t t;
- int32_t gf;
- int32_t gs;
- int16_t u;
- int8_t c;
- int8_t n;
- int8_t f;
- int8_t i[3];
- }a[64];
- int32_t f;
- int8_t g[27];
- int8_t i;
- }trigb[100000];
- int condn;
- int actn;
- struct uprp{
- int16_t vf;
- int16_t ve;
- int8_t p;
- int8_t hp;
- int8_t sp;
- int8_t ep;
- int32_t r;
- int16_t h;
- int16_t f;
- int8_t u[4];
- };
- uint32_t unitn;
- struct unit{
- int32_t c;
- int16_t x;
- int16_t y;
- int16_t i;
- int16_t rt;
- struct uprp p;
- int32_t cr;
- }unitb[2000];
- DWORD strs;
- uint16_t strn;
- uint16_t *stro;
- char *strb;
- uint8_t mrgni;
- uint8_t mrgnn;
- struct mrgn{
- int32_t x;
- int32_t y;
- int32_t xe;
- int32_t ye;
- int16_t s;
- int16_t f;
- }*mrgnb;
- struct uprp *uprpb;
- int uprpn;
- int8_t *ownrb;
- #pragma pack(pop)
- enum state{
- cloaked=1<<0,
- burrowed=1<<1,
- intransit=1<<2,
- hallucinated=1<<3,
- invincible=1<<4,
- };
- enum loc{
- low=1<<0,
- medium=1<<1,
- high=1<<2,
- lowair=1<<3,
- mediumair=1<<4,
- highair=1<<5,
- };
- enum ct{
- ct_none,
- ct_mint,
- ct_trigger,
- ct_condition,
- ct_action,
- ct_condition_type,
- ct_condition_l,
- ct_condition_g,
- ct_condition_n,
- ct_condition_u,
- ct_condition_m,
- ct_condition_r,
- ct_action_type,
- ct_action_l,
- ct_action_s,
- ct_action_w,
- ct_action_t,
- ct_action_gf,
- ct_action_gs,
- ct_action_u,
- ct_action_n,
- ct_player,
- ct_unitprop,
- ct_unitprop_health,
- ct_unitprop_shield,
- ct_unitprop_energy,
- ct_unitprop_resource,
- ct_unitprop_hangar,
- ct_unitprop_cloaked,
- ct_unitprop_burrowed,
- ct_unitprop_transit,
- ct_unitprop_hallucinated,
- ct_unitprop_invincible,
- ct_location,
- ct_location_x,
- ct_location_y,
- ct_location_xe,
- ct_location_ye,
- ct_location_name,
- ct_location_low,
- ct_location_medium,
- ct_location_high,
- ct_location_lowair,
- ct_location_mediumair,
- ct_location_highair,
- ct_unit,
- ct_unit_type,
- ct_unit_player,
- ct_unit_x,
- ct_unit_y,
- ct_unit_health,
- ct_unit_shield,
- ct_unit_energy,
- ct_unit_resource,
- ct_unit_hangar,
- ct_unit_cloaked,
- ct_unit_burrowed,
- ct_unit_transit,
- ct_unit_hallucinated,
- ct_unit_invincible,
- };
- int context=ct_none;
- char str_conditions[24][50]={
- "No Condition",
- "Countdown Timer",
- "Command",
- "Bring",
- "Accumulate",
- "Kill",
- "Command the Most",
- "Command the Most At",
- "Most Kills",
- "Highest Score",
- "Most Resources",
- "Switch",
- "Elapsed Time",
- "Data is a Mission Briefing",
- "Opponents",
- "Deaths",
- "Command the Least",
- "Command the Least At",
- "Least Kills",
- "Lowest Score",
- "Least Resources",
- "Score",
- "Always",
- "Never",
- };
- char str_actions[60][50]={
- "No Action",
- "Victory",
- "Defeat",
- "Preserve Trigger",
- "Wait",
- "Pause Game",
- "Unpause Game",
- "Transmission",
- "Play WAV",
- "Display Text Message",
- "Center View",
- "Create Unit with Properties",
- "Set Mission Objectives",
- "Set Switch",
- "Set Countdown Timer",
- "Run AI Script",
- "Run AI Script At Location",
- "Leaderboard (Control)",
- "Leaderboard (Control At Location)",
- "Leaderboard (Resources)",
- "Leaderboard (Kills)",
- "Leaderboard (Points)",
- "Kill Unit",
- "Kill Unit At Location",
- "Remove Unit",
- "Remove Unit At Location",
- "Set Resources",
- "Set Score",
- "Minimap Ping",
- "Talking Portrait",
- "Mute Unit Speech",
- "Unmute Unit Speech",
- "Leaderboard Computer Players",
- "Leaderboard Goal (Control)",
- "Leaderboard Goal (Control At Location)",
- "Leaderboard Goal (Resources)",
- "Leaderboard Goal (Kills)",
- "Leaderboard Goal (Points)",
- "Move Location",
- "Move Unit",
- "Leaderboard (Greed)",
- "Set Next Scenario",
- "Set Doodad State",
- "Set Invincibility",
- "Create Unit",
- "Set Deaths",
- "Order",
- "Comment",
- "Give Units to Player",
- "Modify Unit Hit Points",
- "Modify Unit Energy",
- "Modify Unit Shield Points",
- "Modify Unit Resource Amount",
- "Modify Unit Hangar Count",
- "Pause Timer",
- "Unpause Timer",
- "Draw",
- "Set Alliance Status",
- "Disable Debug Mode",
- "Enable Debug Mode",
- };
- char str_groups[27][50]={
- "Player 1",
- "Player 2",
- "Player 3",
- "Player 4",
- "Player 5",
- "Player 6",
- "Player 7",
- "Player 8",
- "Player 9",
- "Player 10",
- "Player 11",
- "Player 12",
- "None",
- "Current Player",
- "Foes",
- "Allies",
- "Neutral Players",
- "All players",
- "Force 1",
- "Force 2",
- "Force 3",
- "Force 4",
- "Unknown 1",
- "Unknown 2",
- "Unknown 3",
- "Unknown 4",
- "Non Allied Victory Players",
- };
- char str_units[228][50]={
- "Terran Marine",
- "Terran Ghost",
- "Terran Vulture",
- "Terran Goliath",
- "Goliath Turret",
- "Terran Siege Tank (Tank Mode)",
- "Tank Turret type 1",
- "Terran SCV",
- "Terran Wraith",
- "Terran Science Vessel",
- "Gui Montag (Firebat)",
- "Terran Dropship",
- "Terran Battlecruiser",
- "Vulture Spider Mine",
- "Nuclear Missile",
- "Terran Civilian",
- "Sarah Kerrigan (Ghost)",
- "Alan Schezar (Goliath)",
- "Alan Turret",
- "Jim Raynor (Vulture)",
- "Jim Raynor (Marine)",
- "Tom Kazansky (Wraith)",
- "Magellan (Science Vessel)",
- "Edmund Duke (Siege Tank)",
- "Duke Turret type 1",
- "Edmund Duke (Siege Mode)",
- "Duke Turret type 2",
- "Arcturus Mengsk (Battlecruiser)",
- "Hyperion (Battlecruiser)",
- "Norad II (Battlecruiser)",
- "Terran Siege Tank (Siege Mode)",
- "Tank Turret type 2",
- "Terran Firebat",
- "Scanner Sweep",
- "Terran Medic",
- "Zerg Larva",
- "Zerg Egg",
- "Zerg Zergling",
- "Zerg Hydralisk",
- "Zerg Ultralisk",
- "Zerg Broodling",
- "Zerg Drone",
- "Zerg Overlord",
- "Zerg Mutalisk",
- "Zerg Guardian",
- "Zerg Queen",
- "Zerg Defiler",
- "Zerg Scourge",
- "Torrasque (Ultralisk)",
- "Matriarch (Queen)",
- "Infested Terran",
- "Infested Kerrigan (Infested Terran)",
- "Unclean One (Defiler)",
- "Hunter Killer (Hydralisk)",
- "Devouring One (Zergling)",
- "Kukulza (Mutalisk)",
- "Kukulza (Guardian)",
- "Yggdrasill (Overlord)",
- "Terran Valkyrie",
- "Cocoon",
- "Protoss Corsair",
- "Protoss Dark Templar",
- "Zerg Devourer",
- "Protoss Dark Archon",
- "Protoss Probe",
- "Protoss Zealot",
- "Protoss Dragoon",
- "Protoss High Templar",
- "Protoss Archon",
- "Protoss Shuttle",
- "Protoss Scout",
- "Protoss Arbiter",
- "Protoss Carrier",
- "Protoss Interceptor",
- "Dark Templar (Hero)",
- "Zeratul (Dark Templar)",
- "Tassadar/Zeratul (Archon)",
- "Fenix (Zealot)",
- "Fenix (Dragoon)",
- "Tassadar (Templar)",
- "Mojo (Scout)",
- "Warbringer (Reaver)",
- "Gantrithor (Carrier)",
- "Protoss Reaver",
- "Protoss Observer",
- "Protoss Scarab",
- "Danimoth (Arbiter)",
- "Aldaris (Templar)",
- "Artanis (Scout)",
- "Rhynadon (Badlands)",
- "Bengalaas (Jungle)",
- "Unused type 1",
- "Unused type 2",
- "Scantid (Desert)",
- "Kakaru (Twilight)",
- "Ragnasaur (Ash World)",
- "Ursadon (Ice World)",
- "Zerg Lurker Egg",
- "Raszagal (Dark Templar)",
- "Samir Duran (Ghost)",
- "Alexei Stukov (Ghost)",
- "Map Revealer",
- "Gerard DuGalle (Ghost)",
- "Zerg Lurker",
- "Infested Duran",
- "Disruption Field",
- "Terran Command Center",
- "Terran Comsat Station",
- "Terran Nuclear Silo",
- "Terran Supply Depot",
- "Terran Refinery",
- "Terran Barracks",
- "Terran Academy",
- "Terran Factory",
- "Terran Starport",
- "Terran Control Tower",
- "Terran Science Facility",
- "Terran Covert Ops",
- "Terran Physics Lab",
- "Unused Terran Bldg type 1",
- "Terran Machine Shop",
- "Unused Terran Bldg type 2",
- "Terran Engineering Bay",
- "Terran Armory",
- "Terran Missile Turret",
- "Terran Bunker",
- "Norad II (Crashed Battlecruiser)",
- "Ion Cannon",
- "Uraj Crystal",
- "Khalis Crystal",
- "Infested Command Center",
- "Zerg Hatchery",
- "Zerg Lair",
- "Zerg Hive",
- "Zerg Nydus Canal",
- "Zerg Hydralisk Den",
- "Zerg Defiler Mound",
- "Zerg Greater Spire",
- "Zerg Queen's Nest",
- "Zerg Evolution Chamber",
- "Zerg Ultralisk Cavern",
- "Zerg Spire",
- "Zerg Spawning Pool",
- "Zerg Creep Colony",
- "Zerg Spore Colony",
- "Unused Zerg Bldg",
- "Zerg Sunken Colony",
- "Zerg Overmind (With Shell)",
- "Zerg Overmind",
- "Zerg Extractor",
- "Mature Crysalis",
- "Zerg Cerebrate",
- "Zerg Cerebrate Daggoth",
- "Unused Zerg Bldg 5",
- "Protoss Nexus",
- "Protoss Robotics Facility",
- "Protoss Pylon",
- "Protoss Assimilator",
- "Protoss Unused type 1",
- "Protoss Observatory",
- "Protoss Gateway",
- "Protoss Unused type 2",
- "Protoss Photon Cannon",
- "Protoss Citadel of Adun",
- "Protoss Cybernetics Core",
- "Protoss Templar Archives",
- "Protoss Forge",
- "Protoss Stargate",
- "Stasis Cell/Prison",
- "Protoss Fleet Beacon",
- "Protoss Arbiter Tribunal",
- "Protoss Robotics Support Bay",
- "Protoss Shield Battery",
- "Khaydarin Crystal Formation",
- "Protoss Temple",
- "Xel'Naga Temple",
- "Mineral Field (Type 1)",
- "Mineral Field (Type 2)",
- "Mineral Field (Type 3)",
- "Cave",
- "Cave-in",
- "Cantina",
- "Mining Platform",
- "Independent Command Center",
- "Independent Starport",
- "Jump Gate",
- "Ruins",
- "Kyadarin Crystal Formation",
- "Vespene Geyser",
- "Warp Gate",
- "Psi Disrupter",
- "Zerg Marker",
- "Terran Marker",
- "Protoss Marker",
- "Zerg Beacon",
- "Terran Beacon",
- "Protoss Beacon",
- "Zerg Flag Beacon",
- "Terran Flag Beacon",
- "Protoss Flag Beacon",
- "Power Generator",
- "Overmind Cocoon",
- "Dark Swarm",
- "Floor Missile Trap",
- "Floor Hatch (UNUSED)",
- "Left Upper Level Door",
- "Right Upper Level Door",
- "Left Pit Door",
- "Right Pit Door",
- "Floor Gun Trap",
- "Left Wall Missile Trap",
- "Left Wall Flame Trap",
- "Right Wall Missile Trap",
- "Right Wall Flame Trap",
- "Start Location",
- "Flag",
- "Young Chrysalis",
- "Psi Emitter",
- "Data Disc",
- "Khaydarin Crystal",
- "Mineral Chunk (Type 1)",
- "Mineral Chunk (Type 2)",
- "Vespene Orb (Protoss Type 1)",
- "Vespene Orb (Protoss Type 2)",
- "Vespene Sac (Zerg Type 1)",
- "Vespene Sac (Zerg Type 2)",
- "Vespene Tank (Terran Type 1)",
- "Vespene Tank (Terran Type 2)",
- };
- char str_mod[12][50]={
- "At least",
- "At most",
- "is set",
- "not set",
- "set",
- "clear",
- "toggle",
- "Set To",
- "Add",
- "Subtract",
- "Exactly",
- "randomize",
- };
- char str_res[3][50]={
- "ore",
- "gas",
- "ore and gas",
- };
- char str_ally[3][50]={
- "Enemy",
- "Ally",
- "Allied Victory",
- };
- char str_order[3][50]={
- "Move",
- "Patrol",
- "Attack",
- };
- char str_score[8][50]={
- "Total",
- "Units",
- "Buildings",
- "Units and Buildings",
- "Kills",
- "Razings",
- "Kills and Razings",
- "Custom",
- };
- int16_t str(const char *s){
- int16_t i=0;
- while(i<strn){
- if(!strcmp(strb-2-2*strn+stro[i],s))return(i+1);
- i++;
- }
- i=1;
- while(i<strn){
- if(!strlen(strb-2-2*strn+stro[i])){
- stro[i]=2+2*strn+strs;
- strb=(char *)realloc(strb,strs+strlen(s)+1);
- strcpy(strb+strs,s);
- strs+=strlen(s)+1;
- return(i+1);
- }
- i++;
- }
- puts("Exceeded string limit.");
- exit(EXIT_FAILURE);
- }
- uint8_t mrgn(int32_t x,int32_t y,int32_t xe,int32_t ye,int16_t f){
- if(mrgni==mrgnn){
- puts("Exceeded location limit.");
- exit(EXIT_FAILURE);
- }
- while((mrgnb+mrgni)->s){
- mrgni++;
- if(mrgni==mrgnn){
- puts("Exceeded location limit.");
- exit(EXIT_FAILURE);
- }
- }
- (mrgnb+mrgni)->x=x;
- (mrgnb+mrgni)->y=y;
- (mrgnb+mrgni)->xe=xe;
- (mrgnb+mrgni)->ye=ye;
- (mrgnb+mrgni)->f=f;
- return(++mrgni);
- }
- uint8_t mrgns(int16_t s){
- uint8_t i=0;
- while((mrgnb+i)->s!=s){
- i++;
- if(i==mrgnn){
- printf("Invalid location string: %s\n",strb-2-2*strn+stro[s-1]);
- exit(EXIT_FAILURE);
- }
- }
- return(i+1);
- }
- void XMLCALL
- startElement(void *userData,const XML_Char *name,const XML_Char **attr){
- if(context==ct_none){
- if(!strcmp(name,"mint")){
- context=ct_mint;
- }
- }else if(context==ct_mint){
- if(!strcmp(name,"trigger")){
- // trigb=(struct trig *)realloc(trigb,sizeof(struct trig)*(trign+1));
- // memset(trigb+trign,0,sizeof(struct trig));
- condn=0;
- actn=0;
- context=ct_trigger;
- }else if(!strcmp(name,"unitprop")){
- struct uprp *u=&uprpb[uprpn];
- u->vf=-1;
- u->ve=-1;
- context=ct_unitprop;
- }else if(!strcmp(name,"location")){
- mrgn(0,0,0,0,0);
- context=ct_location;
- }else if(!strcmp(name,"unit")){
- // unitb=(struct unit *)realloc(unitb,sizeof(struct unit)*(unitn+1));
- // memset(unitb+unitn,0,sizeof(struct unit));
- struct unit *unit=unitb+unitn;
- unit->p.vf=-1;
- unit->p.ve=-1;
- context=ct_unit;
- }
- }else if(context==ct_trigger){
- if(!strcmp(name,"condition")){
- if(condn==16){
- puts("Exceeded condition limit.");
- exit(EXIT_FAILURE);
- }
- context=ct_condition;
- }else if(!strcmp(name,"action")){
- if(actn==64){
- puts("Exceeded action limit.");
- exit(EXIT_FAILURE);
- }
- context=ct_action;
- }else if(!strcmp(name,"player")){
- context=ct_player;
- }else if(!strcmp(name,"ptf")){
- (trigb+trign)->f|=1<<2;
- }
- }else if(context==ct_condition){
- if(!strcmp(name,"type")){
- context=ct_condition_type;
- }else if(!strcmp(name,"l")){
- context=ct_condition_l;
- }else if(!strcmp(name,"g")){
- context=ct_condition_g;
- }else if(!strcmp(name,"n")){
- context=ct_condition_n;
- }else if(!strcmp(name,"u")){
- context=ct_condition_u;
- }else if(!strcmp(name,"m")){
- context=ct_condition_m;
- }else if(!strcmp(name,"r")){
- context=ct_condition_r;
- }
- }else if(context==ct_action){
- if(!strcmp(name,"type")){
- context=ct_action_type;
- }else if(!strcmp(name,"l")){
- context=ct_action_l;
- }else if(!strcmp(name,"s")){
- context=ct_action_s;
- }else if(!strcmp(name,"w")){
- context=ct_action_w;
- }else if(!strcmp(name,"t")){
- context=ct_action_t;
- }else if(!strcmp(name,"gf")){
- context=ct_action_gf;
- }else if(!strcmp(name,"gs")){
- context=ct_action_gs;
- }else if(!strcmp(name,"u")){
- context=ct_action_u;
- }else if(!strcmp(name,"n")){
- context=ct_action_n;
- }else if(!strcmp(name,"adf")){
- struct trig::act *act=&(trigb+trign)->a[actn];
- act->f|=1<<2;
- }
- }else if(context==ct_unitprop){
- struct uprp *u=&uprpb[uprpn];
- if(!strcmp(name,"health")){
- context=ct_unitprop_health;
- }else if(!strcmp(name,"shield")){
- context=ct_unitprop_shield;
- }else if(!strcmp(name,"energy")){
- context=ct_unitprop_energy;
- }else if(!strcmp(name,"resource")){
- context=ct_unitprop_resource;
- }else if(!strcmp(name,"hangar")){
- context=ct_unitprop_hangar;
- }else if(!strcmp(name,"cloaked")){
- u->f|=cloaked;
- context=ct_unitprop_cloaked;
- }else if(!strcmp(name,"burrowed")){
- u->f|=burrowed;
- context=ct_unitprop_burrowed;
- }else if(!strcmp(name,"transit")){
- u->f|=intransit;
- context=ct_unitprop_transit;
- }else if(!strcmp(name,"hallucinated")){
- u->f|=hallucinated;
- context=ct_unitprop_hallucinated;
- }else if(!strcmp(name,"invincible")){
- u->f|=invincible;
- context=ct_unitprop_invincible;
- }
- }else if(context==ct_location){
- struct mrgn *m=&mrgnb[mrgni-1];
- if(!strcmp(name,"x")){
- context=ct_location_x;
- }else if(!strcmp(name,"y")){
- context=ct_location_y;
- }else if(!strcmp(name,"xe")){
- context=ct_location_xe;
- }else if(!strcmp(name,"ye")){
- context=ct_location_ye;
- }else if(!strcmp(name,"name")){
- context=ct_location_name;
- }else if(!strcmp(name,"low")){
- m->f|=low;
- context=ct_location_low;
- }else if(!strcmp(name,"medium")){
- m->f|=medium;
- context=ct_location_medium;
- }else if(!strcmp(name,"high")){
- m->f|=high;
- context=ct_location_high;
- }else if(!strcmp(name,"lowair")){
- m->f|=lowair;
- context=ct_location_lowair;
- }else if(!strcmp(name,"mediumair")){
- m->f|=mediumair;
- context=ct_location_mediumair;
- }else if(!strcmp(name,"highair")){
- m->f|=highair;
- context=ct_location_highair;
- }
- }else if(context==ct_unit){
- struct unit *unit=&unitb[unitn];
- if(!strcmp(name,"type")){
- context=ct_unit_type;
- }else if(!strcmp(name,"player")){
- context=ct_unit_player;
- }else if(!strcmp(name,"x")){
- context=ct_unit_x;
- }else if(!strcmp(name,"y")){
- context=ct_unit_y;
- }else if(!strcmp(name,"health")){
- context=ct_unit_health;
- }else if(!strcmp(name,"shield")){
- context=ct_unit_shield;
- }else if(!strcmp(name,"energy")){
- context=ct_unit_energy;
- }else if(!strcmp(name,"resource")){
- context=ct_unit_resource;
- }else if(!strcmp(name,"hangar")){
- context=ct_unit_hangar;
- }else if(!strcmp(name,"cloaked")){
- unit->p.f|=cloaked;
- context=ct_unit_cloaked;
- }else if(!strcmp(name,"burrowed")){
- unit->p.f|=burrowed;
- context=ct_unit_burrowed;
- }else if(!strcmp(name,"transit")){
- unit->p.f|=intransit;
- context=ct_unit_transit;
- }else if(!strcmp(name,"hallucinated")){
- unit->p.f|=hallucinated;
- context=ct_unit_hallucinated;
- }else if(!strcmp(name,"invincible")){
- unit->p.f|=invincible;
- context=ct_unit_invincible;
- }
- }
- }
- void XMLCALL
- endElement(void *userData,const XML_Char *name){
- if(context==ct_mint){
- if(!strcmp(name,"mint")){
- context=ct_none;
- }
- }else if(context==ct_trigger){
- if(!strcmp(name,"trigger")){
- trign++;
- context=ct_mint;
- }
- }else if(context==ct_condition){
- if(!strcmp(name,"condition")){
- condn++;
- context=ct_trigger;
- }
- }else if(context==ct_action){
- if(!strcmp(name,"action")){
- actn++;
- context=ct_trigger;
- }
- }else if(context==ct_player){
- if(!strcmp(name,"player")){
- context=ct_trigger;
- }
- }else if(context==ct_condition_type||
- context==ct_condition_l||
- context==ct_condition_g||
- context==ct_condition_n||
- context==ct_condition_u||
- context==ct_condition_m||
- context==ct_condition_r){
- context=ct_condition;
- }else if(context==ct_action_type||
- context==ct_action_l||
- context==ct_action_s||
- context==ct_action_w||
- context==ct_action_t||
- context==ct_action_gf||
- context==ct_action_gs||
- context==ct_action_u||
- context==ct_action_n){
- context=ct_action;
- }else if(context==ct_unitprop){
- uprpn++;
- context=ct_mint;
- }else if(context==ct_unitprop_health||
- context==ct_unitprop_shield||
- context==ct_unitprop_energy||
- context==ct_unitprop_resource||
- context==ct_unitprop_hangar||
- context==ct_unitprop_cloaked||
- context==ct_unitprop_burrowed||
- context==ct_unitprop_transit||
- context==ct_unitprop_hallucinated||
- context==ct_unitprop_invincible){
- context=ct_unitprop;
- }else if(context==ct_location){
- context=ct_mint;
- }else if(context==ct_location_x||
- context==ct_location_y||
- context==ct_location_xe||
- context==ct_location_ye||
- context==ct_location_name||
- context==ct_location_low||
- context==ct_location_medium||
- context==ct_location_high||
- context==ct_location_lowair||
- context==ct_location_mediumair||
- context==ct_location_highair){
- context=ct_location;
- }else if(context==ct_unit){
- unitn++;
- context=ct_mint;
- }else if(context==ct_unit_type||
- context==ct_unit_player||
- context==ct_unit_x||
- context==ct_unit_y||
- context==ct_unit_health||
- context==ct_unit_shield||
- context==ct_unit_energy||
- context==ct_unit_resource||
- context==ct_unit_hangar||
- context==ct_unit_cloaked||
- context==ct_unit_burrowed||
- context==ct_unit_transit||
- context==ct_unit_hallucinated||
- context==ct_unit_invincible){
- context=ct_unit;
- }
- }
- void XMLCALL
- charData(void *userData,const XML_Char *string,int len){
- char s[len+1];
- memcpy(s,string,len);
- s[len]=0;
- struct trig::cond *cond=&(trigb+trign)->c[condn];
- struct trig::act *act=&(trigb+trign)->a[actn];
- struct uprp *u=&uprpb[uprpn];
- struct mrgn *m=&mrgnb[mrgni-1];
- struct unit *unit=&unitb[unitn];
- if(context==ct_condition_type){
- int i=0;
- while(i<24){
- if(!strcmp(s,str_conditions[i]))break;
- i++;
- }
- if(i==24){
- printf("Invalid condition type: %s\n",s);
- exit(EXIT_FAILURE);
- }
- cond->c=i;
- }else if(context==ct_condition_l){
- cond->l=mrgns(str(s));
- }else if(context==ct_condition_g){
- int i=0;
- while(i<27){
- if(!strcmp(s,str_groups[i]))break;
- i++;
- }
- if(i==27){
- char *se;
- i=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid condition g: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }
- cond->g=i;
- }else if(context==ct_condition_n){
- char *se;
- uint32_t i=strtoll(s,&se,0);
- cond->n=i;
- if(se==s){
- printf("Invalid condition n: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_condition_u){
- int i=0;
- while(i<228){
- if(!strcmp(s,str_units[i]))break;
- i++;
- }
- if(i==228){
- char *se;
- i=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid condition u: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }
- cond->u=i;
- }else if(context==ct_condition_m){
- int i=0;
- while(i<12){
- if(!strcmp(s,str_mod[i]))break;
- i++;
- }
- if(i==12){
- printf("Invalid condition m: %s\n",s);
- exit(EXIT_FAILURE);
- }
- cond->m=i;
- }else if(context==ct_condition_r){
- int i=0;
- while(i<3){
- if(!strcmp(s,str_res[i]))break;
- i++;
- }
- if(i==3){
- i=0;
- while(i<8){
- if(!strcmp(s,str_score[i]))break;
- i++;
- }
- if(i==8){
- char *se;
- i=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid condition r: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }
- }
- cond->r=i;
- }else if(context==ct_action_type){
- int i=0;
- while(i<60){
- if(!strcmp(s,str_actions[i]))break;
- i++;
- }
- if(i==60){
- printf("Invalid action type: %s\n",s);
- exit(EXIT_FAILURE);
- }
- act->c=i;
- }else if(context==ct_action_l){
- act->l=mrgns(str(s));
- }else if(context==ct_action_s){
- act->s=str(s);
- }else if(context==ct_action_w){
- act->w=str(s);
- }else if(context==ct_action_t){
- char *se;
- act->t=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid action t: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_action_gf){
- int i=0;
- while(i<27){
- if(!strcmp(s,str_groups[i]))break;
- i++;
- }
- if(i==27){
- printf("Invalid action gf: %s\n",s);
- exit(EXIT_FAILURE);
- }
- act->gf=i;
- }else if(context==ct_action_gs){
- uint32_t i=0;
- if(act->c==15||act->c==16){ //Run AI Script{, At Location}
- i=*(int32_t *)s;
- }else if(act->c==38||act->c==39||act->c==46){ //Move {Location,Unit}, Order
- i=mrgns(str(s));
- }else{
- while(i<27){
- if(!strcmp(s,str_groups[i]))break;
- i++;
- }
- if(i==27){
- char *se;
- i=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid action gs: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }
- }
- act->gs=i;
- }else if(context==ct_action_u){
- uint16_t i=0;
- while(i<3){
- if(!strcmp(s,str_res[i]))break;
- i++;
- }
- if(i==3){
- i=0;
- while(i<8){
- if(!strcmp(s,str_score[i]))break;
- i++;
- }
- if(i==8){
- i=0;
- while(i<3){
- if(!strcmp(s,str_ally[i]))break;
- i++;
- }
- if(i==3){
- i=0;
- while(i<228){
- if(!strcmp(s,str_units[i]))break;
- i++;
- }
- if(i==228){
- printf("Invalid action u: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }
- }
- }
- act->u=i;
- }else if(context==ct_action_n){
- int i=0;
- while(i<12){
- if(!strcmp(s,str_mod[i]))break;
- i++;
- }
- if(i==12){
- i=0;
- while(i<3){
- if(!strcmp(s,str_order[i]))break;
- i++;
- }
- if(i==3){
- char *se;
- i=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid action n: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }
- }
- act->n=i;
- }else if(context==ct_player){
- int i=0;
- while(i<27){
- if(!strcmp(s,str_groups[i]))break;
- i++;
- }
- if(i==27){
- printf("Invalid player: %s\n",s);
- exit(EXIT_FAILURE);
- }
- (trigb+trign)->g[i]=1;
- }else if(context==ct_unitprop_health){
- char *se;
- u->hp=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unitprop health: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_unitprop_shield){
- char *se;
- u->sp=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unitprop shield: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_unitprop_energy){
- char *se;
- u->ep=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unitprop energy: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_unitprop_resource){
- char *se;
- u->r=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unitprop resource: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_unitprop_hangar){
- char *se;
- u->h=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unitprop hangar: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_location_x){
- char *se;
- m->x=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid location x: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_location_y){
- char *se;
- m->y=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid location y: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_location_xe){
- char *se;
- m->xe=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid location xe: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_location_ye){
- char *se;
- m->ye=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid location ye: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_location_name){
- m->s=str(s);
- }else if(context==ct_unit_type){
- int i=0;
- while(i<228){
- if(!strcmp(str_units[i],s))break;
- i++;
- }
- if(i==228){
- char *se;
- i=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unit type: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }
- unit->i=i;
- }else if(context==ct_unit_player){
- int i=0;
- while(i<27){
- if(!strcmp(str_groups[i],s))break;
- i++;
- }
- if(i==27){
- char *se;
- i=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unit player: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }
- unit->p.p=i;
- }else if(context==ct_unit_x){
- char *se;
- unit->x=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unit x: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_unit_y){
- char *se;
- unit->y=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unit y: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_unit_health){
- char *se;
- unit->p.hp=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unit health: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_unit_shield){
- char *se;
- unit->p.sp=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unit shield: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_unit_energy){
- char *se;
- unit->p.ep=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unit energy: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_unit_resource){
- char *se;
- unit->p.r=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unit resource: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }else if(context==ct_unit_hangar){
- char *se;
- unit->p.h=strtoll(s,&se,0);
- if(se==s){
- printf("Invalid unit hangar: %s\n",s);
- exit(EXIT_FAILURE);
- }
- }
- }
- int
- main(int ac,char **av){
- if(ac!=4){
- puts("Inappropriate arguments");
- exit(EXIT_FAILURE);
- }
- MPQHANDLE mpq;
- assert(SFileOpenArchive(av[1],0,0,&mpq));
- MPQHANDLE scen;
- assert(SFileOpenFileEx(mpq,"staredit\\scenario.chk",0,&scen));
- DWORD size=SFileGetFileSize(scen,NULL);
- char *buf=(char *)malloc(size);
- DWORD read;
- SFileReadFile(scen,buf,size,&read,NULL);
- assert(read==size);
- SFileCloseFile(scen);
- SFileCloseArchive(mpq);
- DWORD off=0;
- while(off<size){
- DWORD chk=8+*(DWORD *)(buf+off+4);
- if(*(DWORD *)(buf+off)==*(DWORD *)"TRIG"){
- trign=(-8+chk)/sizeof(struct trig);
- // trigb=(struct trig *)malloc(-8+chk);
- memcpy(trigb,buf+off+8,-8+chk);
- memmove(buf+off,buf+off+chk,-off-chk+size);
- size-=chk;
- }else if(*(DWORD *)(buf+off)==*(DWORD *)"UNIT"){
- unitn=(-8+chk)/sizeof(struct unit);
- // unitb=(struct unit *)malloc(-8+chk);
- memcpy(unitb,buf+off+8,-8+chk);
- memmove(buf+off,buf+off+chk,-off-chk+size);
- size-=chk;
- }else if(*(DWORD *)(buf+off)==*(DWORD *)"STR "){
- strn=*(uint16_t *)(buf+off+8);
- stro=(uint16_t *)malloc(2*strn);
- memcpy(stro,buf+off+8+2,2*strn);
- strs=-8-2-2*strn+chk;
- strb=(char *)malloc(strs);
- memcpy(strb,buf+off+8+2+2*strn,strs);
- memmove(buf+off,buf+off+chk,-off-chk+size);
- size-=chk;
- }else if(*(DWORD *)(buf+off)==*(DWORD *)"MRGN"){
- mrgnn=(-8+chk)/sizeof(struct mrgn);
- mrgnb=(struct mrgn *)(buf+off+8);
- off+=chk;
- }else if(*(DWORD *)(buf+off)==*(DWORD *)"UPRP"){
- uprpb=(struct uprp *)(buf+off+8);
- off+=chk;
- }else if(*(DWORD *)(buf+off)==*(DWORD *)"OWNR"){
- ownrb=(int8_t *)(buf+off+8);
- off+=chk;
- }else{
- off+=chk;
- }
- }
- XML_Parser parser=XML_ParserCreate(NULL);
- XML_SetElementHandler(parser,startElement,endElement);
- XML_SetCharacterDataHandler(parser,charData);
- FILE *xml=fopen(av[2],"rb");
- fseek(xml,0,SEEK_END);
- long xmlSize=ftell(xml);
- rewind(xml);
- char *xmlbuf=(char *)malloc(xmlSize);
- int len=fread(xmlbuf,1,xmlSize,xml);
- XML_Parse(parser,xmlbuf,len,1);
- XML_ParserFree(parser);
- int mrgnc=0;
- for(int i=0;i<mrgnn;i++){
- if((mrgnb+i)->s){
- mrgnc++;
- }
- }
- DWORD sizeo=size+(8+sizeof(struct unit)*unitn)
- +(8+sizeof(struct trig)*trign)
- +(8+2+2*strn+strs);
- char *bufo=(char *)malloc(sizeo);
- char *bufoa=bufo;
- memcpy(bufoa,buf,size);
- free(buf);
- bufoa+=size;
- memcpy(bufoa,"UNIT",4);
- bufoa+=4;
- unitn*=sizeof(struct unit);
- memcpy(bufoa,&unitn,4);
- bufoa+=4;
- memcpy(bufoa,unitb,unitn);
- // free(unitb);
- bufoa+=unitn;
- memcpy(bufoa,"TRIG",4);
- bufoa+=4;
- trign*=sizeof(struct trig);
- memcpy(bufoa,&trign,4);
- bufoa+=4;
- memcpy(bufoa,trigb,trign);
- // free(trigb);
- bufoa+=trign;
- memcpy(bufoa,"STR ",4);
- bufoa+=4;
- DWORD chk=2+2*strn+strs;
- memcpy(bufoa,&chk,4);
- bufoa+=4;
- memcpy(bufoa,&strn,2);
- bufoa+=2;
- memcpy(bufoa,stro,2*strn);
- free(stro);
- bufoa+=2*strn;
- memcpy(bufoa,strb,strs);
- free(strb);
- bufoa+=strs;
- MPQHANDLE mpqo;
- assert(mpqo=MpqOpenArchiveForUpdate(av[3],MOAU_CREATE_ALWAYS|MOAU_MAINTAIN_LISTFILE,2));
- assert(MpqAddFileFromBuffer(mpqo,(void *)bufo,sizeo,"staredit\\scenario.chk",MAFA_COMPRESS));
- free(bufo);
- MpqCloseUpdatedArchive(mpqo,0);
- printf("Trigger count: %d\n",trign/sizeof(struct trig));
- printf("Unit count: %d\n",unitn/sizeof(struct unit));
- printf("Location count: %d\n",mrgnc);
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement