PrismaticFlower / swbf-unmunge

A totally groovy tool for getting access to game files for a game from 2005.
MIT License
26 stars 4 forks source link

Lua decompiler #30

Open styinx opened 1 year ago

styinx commented 1 year ago

Note: Depends on CMake PR

Recreates (partially incorrect) Lua scripts from scr_ format.

Sources:

Notes about incorrectness:


Sample output:

Lua 4 OP Codes (register values omitted):

OP_PUSHINT
OP_PUSHINT
OP_CALL
OP_GETGLOBAL
OP_PUSHNUM
OP_PUSHSTRING
OP_CALL
OP_PUSHSTRING
OP_CALL
OP_GETGLOBAL
OP_GETGLOBAL
OP_PUSHSTRING
OP_CALL
OP_GETLOCAL
OP_GETLOCAL
OP_GETLOCAL
OP_GETGLOBAL
OP_PUSHINT
OP_PUSHNUM
...
OP_CALL
OP_CALL
OP_PUSHSTRING
OP_CALL
OP_GETGLOBAL
OP_PUSHNUM
OP_PUSHNEGNUM
OP_GETGLOBAL
OP_GETGLOBAL
OP_PUSHSTRING
OP_PUSHNEGNUM
OP_PUSHSTRING
OP_PUSHSTRING
OP_CALL
OP_PUSHNEGNUM
OP_PUSHNEGNUM
OP_CALL
OP_GETGLOBAL
OP_PUSHSTRING
OP_PUSHNEGNUM
OP_GETGLOBAL
OP_PUSHSTRING
OP_CALL
OP_PUSHNUM
OP_CALL
OP_PUSHSTRING
OP_GETGLOBAL
OP_PUSHINT
OP_END
OP_CALL
OP_GETGLOBAL
OP_CALL
OP_CLOSURE
OP_SETGLOBAL
OP_PUSHSTRING
OP_GETGLOBAL
OP_PUSHINT
OP_END
OP_PUSHSTRING
OP_CALL
OP_PUSHINT
OP_PUSHSTRING
OP_CALL
OP_GETGLOBAL

Sample output:

  AddMissionObjective(1,"orange","level.yav2.objectives.1")
  AddMissionObjective(0,"orange","level.yav2.objectives.1")
  SetPlayerTeamDifficultyEasy(3)
  SetEnemyTeamDifficultyEasy(3)
  SetPlayerTeamDifficultyMedium(3)
  SetEnemyTeamDifficultyMedium(505)
  SetTeamAggressiveness(0,0)
  SetTeamAggressiveness(1,0)
  SetMaxFlyHeight(489)
  SetMaxPlayerFlyHeight(489)
  ReadDataFile("sound\yav.lvl;yav2gcw")
  ReadDataFile("SIDE\all.lvl","all_hover_combatspeeder","all_inf_basic","all_inf_lukeskywalker","all_inf_smuggler")
  ReadDataFile("SIDE\imp.lvl","imp_fly_tiefighter","imp_inf_basic","imp_inf_dark_trooper","imp_inf_darthvader","imp_walk_atst")
  SetTeamName(0,"Alliance")
  SetTeamIcon(0,"all_icon")
  AddUnitClass(0,"all_inf_soldier",10)
  AddUnitClass(0,"all_inf_vanguard",2)
  AddUnitClass(0,"all_inf_pilot",3)
  AddUnitClass(0,"all_inf_marksman",3)
  AddUnitClass(0,"all_inf_smuggler",2)
  ...
  SetPlanetaryBonusVoiceOver(0,1,4,"all_bonus_imp_sabotage")
  SetPlanetaryBonusVoiceOver(0,0,5,"")
  SetPlanetaryBonusVoiceOver(0,1,5,"")
  SetPlanetaryBonusVoiceOver(0,0,6,"all_bonus_all_training")
  SetPlanetaryBonusVoiceOver(0,1,6,"all_bonus_imp_training")
  SetAttackingTeam(2)
  AddCameraShot(0.998324,0.042165,-0.039592,0.001672,2.729886,-49.061783,-56.202015)
  AddCameraShot(0.394474,-0.064969,-0.904423,-0.148957,-42.978031,-33.685440,-31.236471)
  AddCameraShot(0.499178,-0.030334,-0.864374,-0.052527,-46.470646,-46.574200,89.658791)
PrismaticFlower commented 1 year ago

Hi! Sorry about the slow response! I'm really sorry to say I don't have time right now to look through this PR properly. It seems like very interesting work and quite a useful addition to the tool though.

Could you attach a .zip of a release build of the PR here? That'd let interested people use these changes even though they haven't been merged.

styinx commented 1 year ago

Hey, no worries ;) We already talked about this in private chat if you recall.

As mentioned in the comments, this branch is not yet ready for a merge. Unfortunately, I got stuck with some aspects of the reassembly. That's why I created the PR for others to look over it (as you already said).

Feel free to point out any issues.

Cheers!

Attached, you find a debug and release build. bin.zip

PrismaticFlower commented 1 year ago

We already talked about this in private chat if you recall. Ah sorry yes, once you mentioned it I did. Sorry about forgetting that!