rofl0r / agsutils

contains utils for AGS: game extractor, repacker, disassembler and assembler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

agsutils by rofl0r
==================

tools for (un)packing, disassembling, modifying and recompiling ags games.

agsex:
  runs agstract and agscriptxtract, then creates a Makefile with rules
  to quickly and automatically repack a pack with changed asm files.
  this basically does everything for you automatically.
  can also use `make optimize` to run agsoptimize on all asm files.

agstract:
  extracts the files a game "pack" (.exe) consists of.
  creates a file agspack.info which contains metadata about the
  files included in the pack.
  example:

	agstract 252test.exe FILES
	:::AGStract 0.9.1 by rofl0r:::
	252test.exe: version 10, containing 6 files.
	ac2game.dta -> FILES/ac2game.dta
	acsprset.spr -> FILES/acsprset.spr
	agsfnt0.wfn -> FILES/agsfnt0.wfn
	agsfnt1.wfn -> FILES/agsfnt1.wfn
	agsfnt2.wfn -> FILES/agsfnt2.wfn
	room1.crm -> FILES/room1.crm

  agstract can also extract speech.vox and audio.vox files.
  make sure to use a different output directory, otherwise your
  agspack.info will be overwritten.

  in some games, speech.vox is insanely big because the speech files are
  saved in studio quality.

  i achieved good results by converting them to 16Khz via ffmpeg:

      for i in SPEECH/*.ogg ; do
        ffmpeg -i "$i" -c:a libvorbis -ar 16384 tmp.oga && mv tmp.oga "$i"
      done

  then repacking it with agspack, which results in about 6x space improvement.

  for audio.vox, you might want to use -b:a 80k instead of -ar 16384.
  this shrinks input files by about 400% with almost CD-like quality.

agspack:
  takes the files created by agstract and makes a new bundle out of it.
  example:

	agspack FILES/ 252mytest.ags
	agspack -e FILES/ 252mytest.exe

  without arguments, agspack produces a game pack missing the original
  windows exe stub, but is compatible with the opensource AGS engine,
  as well as with scummvm ags port.
  that way, a game is about 500 KB smaller after extract and repack than it
  originally was.

  using the -e option, the original exestub is prepended to the game pack,
  and the offset to the start of the pack data encoded into the end signature,
  which reproduces the fully working windows executable with the new content.

  note that agspack always produces a version 20/30 packfile, compatible only
  with ags 3.0 or newer, so if your exe stub is from an earlier game, it
  will fail to recognize the attached game data. in such a case you can
  use the exestub from a newer version, e.g.
  https://github.com/ags-archives/engines/blob/master/ags302sp1/acwin.exe
  save it as agspack.exestub in your extract directory.

agscriptxtract:
  detects and unpacks all binary scripts embedded in room and game files.
  the compiled scripts are stored with a .o extension, the disassembled files with .s.
  example:

        mkdir OBJ ; cd OBJ
	agscriptxtract ../FILES
	disassembling globalscript.o -> globalscript.s
	disassembling room1.o -> room1.s

agsdisas:
  disassembles a single .o file to .s. useful to compare a re-assembled file with the original.
  example:

	agsdisas room1.o room1.s
	disassembling room1.o -> room1.s

agssemble:
  creates a compiled object file from a .s assembly file.
  example:

	agssemble room1.s
	creates a new room1.o (you will notice filesize/date has changed)

  the compiled object file will miss unused strings and thus be smaller than the original.
  also imports and exports cover only really used ones.

agsinject:
  once you have recompiled an .o file with agssemble, you can inject it into the original
  container file (either a .crm room file or a game file like "ac2game.dta")
  example:

	agsinject 0 OBJ/room1.o FILES/room1.crm

	injects room1.o at the first found script (0) in room1.crm.
	rooms have only 1 script so you must always use 0.
	for ac2game.dta kinda gamefiles, the index is i.e. 0 for the globalscript,
	1 for the dialogscript (if one exists), otherwise 1 is the first gamescript, etc.

  after you injected your .o file, the next thing you want to do is agspack it all up again.
  then you can test your changes in the ags engine.

agsprite:
  a tool to extract sprites from acsprset.spr files, and to create a new one
  from a directory full of extracted sprites. has several options to create
  smaller spritecache files than original, for example by converting all
  true-color images to high-color, which is almost impossible to differentiate
  visually.
  unfortunately ags saves a "uses alpha channel" flag for every sprite in a
  different file.
  if it was set, a picture converted from 32 to 16bit will become
  invisible, unless it is fixed with `agsalphahack` tool.
  after repacking a .spr file, a new sprindex.dat must be created and the old
  one replaced with it (if one existed). agsprite has an option for that too.
  optionally, the old sprindex.dat can simply be removed by commenting out the
  line with sprindex.dat in agspack.info and reducing the filecount by 1.
  at present, agsprite only creates and accepts TGA files.
  if you want to edit a sprite and your tool can't handle TGA format (unlikely),
  you can still convert the file into a format of your choice with e.g.
  imagemagick's `convert` tool, and then convert it back to TGA before creating
  a new sprite pack.
  run agsprite --help for usage information, and/or check the git log of
  agsprite.c to read a lot of detailed commit messages.

agsalphahack:
  a tool to remove alphachannel flags from gamefiles. can delete either all
  or a single specified sprite number's alpha channel flag. this tool is a
  supplement to agsprite.

agsalphainfo:
  a tool to print alphachannel information for each sprite.

agssim:
  a simple simulator for ags assembly instructions.
  run agssim --help for more info.

agsoptimize:
  a python script which is run on some .s asm files, detecting common inefficient
  patterns emitted by the AGS compiler, and replacing them with more efficient
  versions. using all preset optimization patterns, this improves speed of the
  CPU-heavy (because of a lots of scripts) game "Operation Forklift" by ~15-20%,
  which is almost identical to the number of asm statements it removes.
  another advantage is that the script files become smaller.

ascc:
  the original AGS script compiler with some tweaks to support more C features.
  it's pretty handy to generate assembly code to inject into scripts.
  since ascc is based on the original AGS sources and is written in C++, it's
  available in a different repository: https://github.com/rofl0r/ascc .


compilation:
------------

after acquiration of a C compiler toolchain (optimally GCC) and GNU make
(e.g. on ubuntu: `apt install build-essential`),

simply run `make`.

if you need any special CFLAGS, LDFLAGS etc put them into config.mak
or append them to the make command, i.e. `make CFLAGS="-O2 -g"`

compilation on windos:
----------------------

mingw is not supported. it' s a half-baked PoS, which lacks a dozen or more of
the POSIX APIs we require. worse than that, it even has *wrong* prototypes
for some of them, for example it defines mkdir(char*), but the proper prototype
is mkdir(char*, int), so we'd have to litter the code with #ifdefs and remove
parts of the functionality to support it. that's not gonna happen.

use cygwin. with cygwin, every works just fine without *any* changes. you can
even run `make` and it produces files with .exe extensions even though we don't
have a rule for that anywhere. you only need to ship cygwin-1.dll together with
the binaries.

NEW!!! agsutils can now also be compiled using [PellesC](http://www.smorgasbordet.com/pellesc/)
(use [pellescc wrapper](https://github.com/rofl0r/pellescc) to build from Makefile).

alternatively you can use WSL/WSL2 and just use native linux compiler and the
binaries inside the WSL environment.

third-party library requirements:
---------------------------------
none. \o/

supported AGS versions:
-----------------------
like the opensource AGS engine, version 2.3 and 2.4 aren't properly supported
due to lack of available format information. support for those might be
completed at some point in the future.
all versions >= 2.5.0 are supported, and if one of the tools bails out on them
it's considered a bug.

License:
--------
there is a tiny part of code left from the original AGS engine, about 150 LOC in CLib32.c.
it is covered under the artistic license, see file header for details.
all other code is (C) 2012-2019 rofl0r and licensed under the LGPL 2.1+ with the "NO C++"
exception.
the "NO C++" exception means that you are not allowed to convert the code into C++, but
you can link it to C++ code.

About

contains utils for AGS: game extractor, repacker, disassembler and assembler


Languages

Language:C 88.9%Language:Python 4.7%Language:Yacc 4.1%Language:Lex 0.8%Language:Makefile 0.8%Language:Shell 0.5%Language:Assembly 0.2%