- Fixed more byte swapping lackage in p_acs.cpp. A cursory run through Hexen seems to have scripting

working now.



SVN r2524 (trunk)
This commit is contained in:
Randy Heit 2010-08-12 22:39:06 +00:00
parent 7d40b8a9a4
commit 3cf25ad8e5

View file

@ -3491,6 +3491,20 @@ inline int getshort (int *&pc)
return res; return res;
} }
// Read a possibly unaligned four-byte little endian integer.
#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__)
inline int uallong(int &foo)
{
return *foo;
}
#else
inline int uallong(int &foo)
{
unsigned char *bar = (unsigned char *)&foo;
return bar[0] | (bar[1] << 8) | (bar[2] << 16) | (bar[3] << 24);
}
#endif
int DLevelScript::RunScript () int DLevelScript::RunScript ()
{ {
DACSThinker *controller = DACSThinker::ActiveThinker; DACSThinker *controller = DACSThinker::ActiveThinker;
@ -3605,7 +3619,8 @@ int DLevelScript::RunScript ()
break; break;
case PCD_PUSHNUMBER: case PCD_PUSHNUMBER:
PushToStack (NEXTWORD); PushToStack (uallong(pc[0]));
pc++;
break; break;
case PCD_PUSHBYTE: case PCD_PUSHBYTE:
@ -3707,35 +3722,35 @@ int DLevelScript::RunScript ()
case PCD_LSPEC1DIRECT: case PCD_LSPEC1DIRECT:
temp = NEXTBYTE; temp = NEXTBYTE;
LineSpecials[temp] (activationline, activator, backSide, LineSpecials[temp] (activationline, activator, backSide,
pc[0], 0, 0, 0, 0); uallong(pc[0]), 0, 0, 0, 0);
pc += 1; pc += 1;
break; break;
case PCD_LSPEC2DIRECT: case PCD_LSPEC2DIRECT:
temp = NEXTBYTE; temp = NEXTBYTE;
LineSpecials[temp] (activationline, activator, backSide, LineSpecials[temp] (activationline, activator, backSide,
pc[0], pc[1], 0, 0, 0); uallong(pc[0]), uallong(pc[1]), 0, 0, 0);
pc += 2; pc += 2;
break; break;
case PCD_LSPEC3DIRECT: case PCD_LSPEC3DIRECT:
temp = NEXTBYTE; temp = NEXTBYTE;
LineSpecials[temp] (activationline, activator, backSide, LineSpecials[temp] (activationline, activator, backSide,
pc[0], pc[1], pc[2], 0, 0); uallong(pc[0]), uallong(pc[1]), uallong(pc[2]), 0, 0);
pc += 3; pc += 3;
break; break;
case PCD_LSPEC4DIRECT: case PCD_LSPEC4DIRECT:
temp = NEXTBYTE; temp = NEXTBYTE;
LineSpecials[temp] (activationline, activator, backSide, LineSpecials[temp] (activationline, activator, backSide,
pc[0], pc[1], pc[2], pc[3], 0); uallong(pc[0]), uallong(pc[1]), uallong(pc[2]), uallong(pc[3]), 0);
pc += 4; pc += 4;
break; break;
case PCD_LSPEC5DIRECT: case PCD_LSPEC5DIRECT:
temp = NEXTBYTE; temp = NEXTBYTE;
LineSpecials[temp] (activationline, activator, backSide, LineSpecials[temp] (activationline, activator, backSide,
pc[0], pc[1], pc[2], pc[3], pc[4]); uallong(pc[0]), uallong(pc[1]), uallong(pc[2]), uallong(pc[3]), uallong(pc[4]));
pc += 5; pc += 5;
break; break;
@ -4642,7 +4657,8 @@ int DLevelScript::RunScript ()
break; break;
case PCD_DELAYDIRECT: case PCD_DELAYDIRECT:
statedata = NEXTWORD + (fmt == ACS_Old && gameinfo.gametype == GAME_Hexen); statedata = uallong(pc[0]) + (fmt == ACS_Old && gameinfo.gametype == GAME_Hexen);
pc++;
if (statedata > 0) if (statedata > 0)
{ {
state = SCRIPT_Delayed; state = SCRIPT_Delayed;
@ -4664,7 +4680,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_RANDOMDIRECT: case PCD_RANDOMDIRECT:
PushToStack (Random (pc[0], pc[1])); PushToStack (Random (uallong(pc[0]), uallong(pc[1])));
pc += 2; pc += 2;
break; break;
@ -4679,7 +4695,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_THINGCOUNTDIRECT: case PCD_THINGCOUNTDIRECT:
PushToStack (ThingCount (pc[0], -1, pc[1], -1)); PushToStack (ThingCount (uallong(pc[0]), -1, uallong(pc[1]), -1));
pc += 2; pc += 2;
break; break;
@ -4706,7 +4722,8 @@ int DLevelScript::RunScript ()
case PCD_TAGWAITDIRECT: case PCD_TAGWAITDIRECT:
state = SCRIPT_TagWait; state = SCRIPT_TagWait;
statedata = NEXTWORD; statedata = uallong(pc[0]);
pc++;
break; break;
case PCD_POLYWAIT: case PCD_POLYWAIT:
@ -4717,7 +4734,8 @@ int DLevelScript::RunScript ()
case PCD_POLYWAITDIRECT: case PCD_POLYWAITDIRECT:
state = SCRIPT_PolyWait; state = SCRIPT_PolyWait;
statedata = NEXTWORD; statedata = uallong(pc[0]);
pc++;
break; break;
case PCD_CHANGEFLOOR: case PCD_CHANGEFLOOR:
@ -4726,7 +4744,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_CHANGEFLOORDIRECT: case PCD_CHANGEFLOORDIRECT:
ChangeFlat (pc[0], pc[1], 0); ChangeFlat (uallong(pc[0]), uallong(pc[1]), 0);
pc += 2; pc += 2;
break; break;
@ -4736,7 +4754,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_CHANGECEILINGDIRECT: case PCD_CHANGECEILINGDIRECT:
ChangeFlat (pc[0], pc[1], 1); ChangeFlat (uallong(pc[0]), uallong(pc[1]), 1);
pc += 2; pc += 2;
break; break;
@ -4820,7 +4838,8 @@ int DLevelScript::RunScript ()
case PCD_SCRIPTWAITDIRECT: case PCD_SCRIPTWAITDIRECT:
state = SCRIPT_ScriptWait; state = SCRIPT_ScriptWait;
statedata = NEXTWORD; statedata = uallong(pc[0]);
pc++;
PutLast (); PutLast ();
break; break;
@ -4830,14 +4849,14 @@ int DLevelScript::RunScript ()
break; break;
case PCD_CASEGOTO: case PCD_CASEGOTO:
if (STACK(1) == NEXTWORD) if (STACK(1) == uallong(pc[0]))
{ {
pc = activeBehavior->Ofs2PC (LittleLong(*pc)); pc = activeBehavior->Ofs2PC (uallong(pc[1]));
sp--; sp--;
} }
else else
{ {
pc++; pc += 2;
} }
break; break;
@ -4845,7 +4864,7 @@ int DLevelScript::RunScript ()
// The count and jump table are 4-byte aligned // The count and jump table are 4-byte aligned
pc = (int *)(((size_t)pc + 3) & ~3); pc = (int *)(((size_t)pc + 3) & ~3);
{ {
int numcases = NEXTWORD; int numcases = uallong(pc[0]); pc++;
int min = 0, max = numcases-1; int min = 0, max = numcases-1;
while (min <= max) while (min <= max)
{ {
@ -5173,7 +5192,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_SETFONTDIRECT: case PCD_SETFONTDIRECT:
DoSetFont (pc[0]); DoSetFont (uallong(pc[0]));
pc++; pc++;
break; break;
@ -5462,7 +5481,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_SETGRAVITYDIRECT: case PCD_SETGRAVITYDIRECT:
level.gravity = (float)pc[0] / 65536.f; level.gravity = (float)uallong(pc[0]) / 65536.f;
pc++; pc++;
break; break;
@ -5473,7 +5492,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_SETAIRCONTROLDIRECT: case PCD_SETAIRCONTROLDIRECT:
level.aircontrol = pc[0]; level.aircontrol = uallong(pc[0]);
pc++; pc++;
G_AirControlChanged (); G_AirControlChanged ();
break; break;
@ -5484,7 +5503,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_SPAWNDIRECT: case PCD_SPAWNDIRECT:
PushToStack (DoSpawn (pc[0], pc[1], pc[2], pc[3], pc[4], pc[5], false)); PushToStack (DoSpawn (uallong(pc[0]), uallong(pc[1]), uallong(pc[2]), uallong(pc[3]), uallong(pc[4]), uallong(pc[5]), false));
pc += 6; pc += 6;
break; break;
@ -5494,7 +5513,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_SPAWNSPOTDIRECT: case PCD_SPAWNSPOTDIRECT:
PushToStack (DoSpawnSpot (pc[0], pc[1], pc[2], pc[3], false)); PushToStack (DoSpawnSpot (uallong(pc[0]), uallong(pc[1]), uallong(pc[2]), uallong(pc[3]), false));
pc += 4; pc += 4;
break; break;
@ -5550,7 +5569,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_GIVEINVENTORYDIRECT: case PCD_GIVEINVENTORYDIRECT:
GiveInventory (activator, FBehavior::StaticLookupString (pc[0]), pc[1]); GiveInventory (activator, FBehavior::StaticLookupString (uallong(pc[0])), uallong(pc[1]));
pc += 2; pc += 2;
break; break;
@ -5580,7 +5599,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_TAKEINVENTORYDIRECT: case PCD_TAKEINVENTORYDIRECT:
TakeInventory (activator, FBehavior::StaticLookupString (pc[0]), pc[1]); TakeInventory (activator, FBehavior::StaticLookupString (uallong(pc[0])), uallong(pc[1]));
pc += 2; pc += 2;
break; break;
@ -5595,7 +5614,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_CHECKINVENTORYDIRECT: case PCD_CHECKINVENTORYDIRECT:
PushToStack (CheckInventory (activator, FBehavior::StaticLookupString (pc[0]))); PushToStack (CheckInventory (activator, FBehavior::StaticLookupString (uallong(pc[0]))));
pc += 1; pc += 1;
break; break;
@ -5699,7 +5718,7 @@ int DLevelScript::RunScript ()
break; break;
case PCD_SETMUSICDIRECT: case PCD_SETMUSICDIRECT:
S_ChangeMusic (FBehavior::StaticLookupString (pc[0]), pc[1]); S_ChangeMusic (FBehavior::StaticLookupString (uallong(pc[0])), uallong(pc[1]));
pc += 3; pc += 3;
break; break;
@ -5714,7 +5733,7 @@ int DLevelScript::RunScript ()
case PCD_LOCALSETMUSICDIRECT: case PCD_LOCALSETMUSICDIRECT:
if (activator == players[consoleplayer].mo) if (activator == players[consoleplayer].mo)
{ {
S_ChangeMusic (FBehavior::StaticLookupString (pc[0]), pc[1]); S_ChangeMusic (FBehavior::StaticLookupString (uallong(pc[0])), uallong(pc[1]));
} }
pc += 3; pc += 3;
break; break;