Commit Graph
56 Commits
Author SHA1 Message Date
Nunuhara Cabbage 1a0a0e0c12 debugger: breakpoints
This is implemented by inserting special opcodes into the game's code.
When the breakpoint handler is finished, it returns the original opcode
so that execute_instruction can continue executing normally.

E.g.

* start xsystem4 with --debug option to drop into debugger immediately
* run (bp "game_main")
* ^d or \exit to close debugger REPL
* ...drop into a debugger REPL again at the game_main function
2020-08-09 12:41:33 -07:00
Nunuhara Cabbage bd8ad5583a Read configuration from .xsys4rc config file
global config in $XSYSTEM4_HOME/.xsys4rc (default ~/.xsys4rc)
game-specific config in <game-dir>/.xsys4rc

Supported options so far are "font-mincho" and "font-gothic". Syntax is
the same as System40.ini. E.g.

    font-mincho = "/home/user/.fonts/msmincho.ttc"
2020-08-07 19:12:51 -07:00
Nunuhara Cabbage 3f91d84005 Add acxdump and acxbuild tools
Tools for dumping .acx files to csv format and rebuilding them.
2020-08-05 18:59:28 -07:00
Nunuhara Cabbage 3d70c81404 ainedit: support reading HLL declarations 2020-08-01 22:19:00 -07:00
Nunuhara Cabbage 44802acb48 aindump: support Hentai Labyrinth
Even though this game is still ain v14, it makes an incompatible change
to the file format: struct definitions now contain a list of functions
at the end (I believe this is a listing of the struct's vtable).

There is now a system for tracking the minor version of the ain file
format. This is a made up value, determined by the file name of the ain
file.

This commit also fixes an issue where the empty string was being added
as a new string to the string table when rebuilding ain files with
ainedit.
2020-07-31 20:42:08 -07:00
Nunuhara Cabbage c2aae50dca Various improvements to SengokuRanceFont/fnl 2020-07-30 20:55:17 -07:00
Nunuhara Cabbage a8b2e91053 alice-ar: fix bug when extracting linked webp
Need to pass the archive as an argument so that base CGs can be
retrieved.
2020-07-30 20:41:24 -07:00
Nunuhara Cabbage 58da6dc167 Refactor system4.h
Move xsystem4-specific declarations to xsystem4.h.
2020-07-12 09:17:52 -07:00
Nunuhara Cabbage f9eaef7717 Fix encoding issue with macro generation
Fixes #2.

The problem here was that init_member_functions assumed ASCII or SJIS
encoding of function/struct names in the ain file. Now it will convert
to UTF-8 when analyzing member functions.

This commit also removes the --ain-encoding option to ainedit.
--output-encoding should always match the encoding of the input ain
file. --transcode can be used to change the encoding before running
running further ainedit commands.
2020-07-11 11:10:18 -07:00
Nunuhara Cabbage d3928c774d jaf: messages and char constants 2020-07-05 22:29:45 -07:00
Nunuhara Cabbage 8bf7e2aa2b jaf: function types 2020-07-05 16:26:06 -07:00
Nunuhara Cabbage 5bc3a05167 ainedit: initial .pje support
Support building from project files used by the official SDK.
2020-07-01 09:41:17 -07:00
Nunuhara Cabbage fd60c6329b jaf: arrays 2020-06-27 13:35:09 -07:00
Nunuhara Cabbage a2012a56ce jaf: support system calls
Only for ain version < 11. Starting with v11 system calls are actually
HLL calls.
2020-06-22 10:14:11 -07:00
Nunuhara Cabbage b41275f6f4 jaf: support multiple input files 2020-06-21 16:50:04 -07:00
Nunuhara Cabbage d4f1b5ba46 ainedit: support creating new ain files
This is mainly for testing purposes. Defaults to creating an ain v4
file, which is the same version produced by the SDK compiler.

Also various small improvements so that output matches the SDK compiler:
* add "0" function (currently does nothing)
* add "NULL" function
* compile null return at the end of every function
* set main function index in ain file
2020-06-21 14:52:05 -07:00
Nunuhara Cabbage 6e3a3e784a jaf: strings and reference types 2020-06-20 21:05:14 -07:00
Nunuhara Cabbage 2908e6fcdc jaf: initial compiler implementation
Supports reading from local variables (no assignment) and arithmetic.
2020-06-16 20:38:29 -07:00
Nunuhara Cabbage d8e21d0323 jaf: support parsing identifiers & function calls 2020-06-14 15:54:59 -07:00
Nunuhara Cabbage e618017e78 ainedit: support parsing .jaf functions 2020-06-13 13:36:39 -07:00
Nunuhara Cabbage 897cbde39c ainedit: initial .jaf support
Initial support for compiling .jaf (System 4 language) files. So far
this is limited to adding struct definitions and declaring new globals.
The actual bytecode compilation is not yet implemented.

This Bison grammar is based on a C grammar and should cover 95% of the
System 4 language syntax already, though many AST nodes are not yet
implemented.
2020-06-10 21:23:00 -07:00
Nunuhara Cabbage 767e2afd57 alice-tools 0.4.0
Fix some Windows-specific issues for alice-ar and update READMEs.
2020-05-23 17:46:00 -07:00
Nunuhara Cabbage 8f38b6141e alice-ar: various improvements
* Can now extract files from .afa version 3 archives
* Can now extract files from .flat files
  * Includes recursively extracting .flat files contained in other
    archive formats
* Added option to extract images only
* Now converts images to PNG format by default
  * WebP format also supported

Because the table of contents is encrypted in .afa version 3 archives,
the support is a bit limited. Only known file types can be extracted and
they do not retain their original filenames (they are given numbered
filenames instead).
2020-05-23 12:33:40 -07:00
Nunuhara Cabbage 9ab13af34e DCF CG support
For alice-ar. This is a wrapper format for QNT CGs. I have no idea what
the additional metadata is for.
2020-05-21 16:30:12 -07:00
Nunuhara Cabbage 05d998886f exdump/exbuild: fix issues with Evenicle2EX.ex
Evenicle2EX.ex uses the previously unknown field data in a different way
that what was assumed. Thanks to that, the unknown data is now more or
less understood:
  * uk0 indicates whether there is a value associated with the field
  * uk1 indicates whether the field is an index
  * uk2 is the value associated with the field, which can be an integer,
    float or string (so far, at least...)

Previously it was assumed that uk2 was a single 32-bit integer, but it
can actually store strings as well. Evenicle 2 is the first game to use
a field with a string value other than the empty string, which breaks
this assumption (the empty string is a 32-bit zero, which is why the old
approach worked).

There is now a new syntax for specifying this data. E.g., a field may
now look like this:
    indexed string s = ""
where it would previously have looked like this:
    string s[1,1,0]

The old syntax is still supported in ainbuild for backwards
compatibility, but is no longer emitted by aindump.

This commit also adds the tool "excmp" which compares two ex files to
see if they are equivalent.
2020-05-18 10:34:43 -07:00
Nunuhara Cabbage b617449178 aindump/ainedit: initial ain v14 support
Support for Evenicle 2 and Haha Ranman.

There are a few changes in v14:
* a number of new instructions (semantics yet unknown)
* HLL function arguments and return values can now be complex types
  (e.g. arrays, enums)
* support for nested arrays (this isn't necessarily new, but it doesn't
  occur in Rance X at all)
2020-05-17 13:21:37 -07:00
Nunuhara Cabbage bf9ce85079 exdump: fix for broken table in Rance 03
Rance03.ex has a broken table in which a field type does not match the
type of the data in the corresponding column. So rather than aborting
with an error, exdump will now print a warning when dumping this file.
2020-05-01 17:55:55 -07:00
Nunuhara Cabbage 094ce848b9 aindump/ainedit: STRUCTREF, etc. macros
Same idea as LOCALREF/GLOBALREF, etc. except for accessing struct
members inside of a member function. This is a bit trickier since it
requires knowing which functions belong to which structs, which isn't
directly encoded in the AIN format.
2020-05-01 16:31:12 -07:00
Nunuhara Cabbage f164480f35 Initial fnl (bitmap) font rendering implementation
Enough to get text on the screen, but it isn't pretty. No antialiasing,
kerning, vertical placement isn't correct, probably the size isn't even
quite correct, etc.
2020-04-25 08:09:13 -07:00
Nunuhara Cabbage 99b375acce alice-ar: support extracting ALD and AFA files
Support whole archive, by-index and by-name extraction of files from ALD
and AFA archives.
2020-04-24 22:49:42 -07:00
Nunuhara Cabbage 15ef8caa91 Add fnldump utility
Add tool for extracting bitmap fonts from .fnl files (font archives).
This is mainly for testing the underlying .fnl reading code, which is
needed for proper font rendering in the MangaGamer version of Sengoku
Rance. In the future this tool could be updated to support rebuilding
font archives, which would allow adding special glyphs, using condensed
fonts, etc.

Credit to CookieWukk for reverse engineering the .fnl file format.
2020-04-08 20:08:45 -07:00
Nunuhara Cabbage 40ce6e2e82 Add webp CG support
For the MangaGamer version of Sengoku Rance. This makes libwebp a
dependency.

These webp files have a non-standard metadata block appended to them
which specifies the base CG that should be used for unfilled pixels,
where "unfilled" means any pixels with a pure magenta color (255,0,255).
2020-04-07 18:41:01 -07:00
Nunuhara Cabbage e4a2e965df Use custom parser for System40.ini
This is not really a standard ini file, so a custom parser is needed to
access all of the information stored in it (specifically, lists like
"LoadDLL").

This commit also makes flex/bison a hard dependency.
2020-03-10 21:36:28 -07:00
Nunuhara Cabbage 3e1919e17c AJP alpha channel support
Add PMS decoder from xsystem35 for AJP alpha mask.
2020-03-08 10:53:23 -07:00
Nunuhara Cabbage 2d1b8dad3a Partial AJP CG support
Support for AJP without alpha channel.
2020-03-07 21:47:09 -08:00
Nunuhara Cabbage 40b67ed7f6 Initial afa archive support
Very incomplete implementation. Capable of reading the file table and
not much else.

Also add the "alice-ar" utility for testing. Eventually this tool should
support modifying ald and afa archives. For now only supports dumping
the afa file table.
2020-02-25 20:34:51 -08:00
Nunuhara Cabbage be1b5ecc8f Use abstract archive interface for ALD files
In preparation for AFA support in libsystem4.
2020-02-23 18:49:51 -08:00
Nunuhara Cabbage c58af1c17f exdump: add -d,--decrypt option
For debugging/reversing purposes.
2020-02-22 22:04:47 -08:00
Nunuhara Cabbage 38048ea9e6 Add exdump utility
Add tool for dumping the contents of .ex files, which contain various
structured data used by the game (tables, lists, trees).

The dump format uses a C-like syntax which should be relatively easy to
parse back in.
2020-02-17 19:51:25 -08:00
Nunuhara Cabbage 608aedb500 Fix various issues with MSYS2/mingw build 2020-02-14 16:29:44 -08:00
Nunuhara Cabbage a76b7149d9 aindump/ainedit: add .CASE pseudo instruction
Add a pseudo instruction to represent switch case labels, along with the
infrastructure to support pseudo instructions in general. .CASE takes
two arguments: a switch:case index (e.g. "12:8") and the value to match
against.

Also, add a --no-strings option to both programs to allow modifying the
code without changing the string/message tables. This is needed for now
since rebuilding the string/message tables (as currently implemented)
causes serious bugs in Rance X (and probably other games).

Running the following command should produce an ain file that is almost
bit-for-bit identical to the input file (the only difference being minor
drift in floating point constants):

    aindump -c --no-strings in.ain | ainedit -c - --no-strings -o
        out.ain in.ain
2020-02-09 15:34:10 -08:00
Nunuhara Cabbage dab8deca42 Add ainedit utility
The ainedit utility is a tool capable of modifying AIN files up to
version 12 (Rance X). As far as I know, this is the first publicly
released tool that can handle AIN files above version 7.

The basic mode of operation is as follows:

* dump the CODE section with aindump
* edit the disassembled bytecode
* assemble & insert the edited bytebode back into the original AIN file
  using ainedit

E.g.

    aindump -c -o out.jam /path/to/Rance10.ain
    $EDITOR out.jam
    ainedit -c out.jam -o out.ain /path/to/Rance10.ain
    mv /path/to/Rance10.ain /path/to/Rance10.ain.backup
    mv out.ain /path/to/Rance10.ain

ainedit is also capable of editing declarations (structures, functions,
etc.) using the JSON (-j) output from aindump.

There is currently one major deficiency in this tool: it does not
rebuild the AIN file's switch table (SWI0 section). This means that you
can't insert or delete instructions, as it would render the addresses
stored in the switch table invalid. I hope to fix this soon.

A number of changes have also been made to the aindump utility, since
these tools need to work together.
2020-02-07 19:49:39 -08:00
Nunuhara Cabbage 167953f33c aindump: dump full enum definitions (incl. values)
This requires scanning through the code for a particular method for each
enum type. Not a great solution, but there's not much else that can be
done here.

Also, use khash.h (from klib) for hash tables.
2020-01-15 21:53:51 -08:00
Nunuhara Cabbage e1f6093565 aindump: fix CALLMETHOD argument in v11+
In ain v11+, the first and only argument to CALLMETHOD is the number of
arguments that are being passed to the method. The calling convention
is:

    PUSH <struct page>
    PUSH <function index>
    PUSH <arg 0>
    ...
    PUSH <arg n>
    CALLMETHOD <n>
2020-01-15 14:29:47 -08:00
Nunuhara Cabbage 74c5b91e0c aindump: enums, iterators, interface objects
Type 82
-------
I am assuming this is an iterator type because it always appears as a
local variable alongside "dummy" variables with "foreach" in their name,
and the naming of the variables suggests an iterator. Probably there is
a new syntax like:

    foreach (iter_var in array_var) { ... }

Type 89
-------
An instance of an interface. This is a 2-valued type (similar to ref
int, etc.) where the first value is the index of a struct page, and the
second value is an index into the struct's vtable.

Any struct that implements an interface gets an array<int> named
"<vtable>" as its first member. This array stores indices into the
global function table. CALLMETHOD now looks up methods in the vtable
rather than the global function table.

Types 92, 93
------------
These are enum types. Type 92 is the normal enum type, and type 93 is
the reference-to-enum type. The "struct type" for these types stores an
index into the enum table.

Types 86, 91
------------
Type 86 only seems to be used as the return value from EnumType::Parse
methods. In the ain file, it has an extra type descriptor, similar to an
array type. This extra type descriptor always has data type 91, and its
struct type is an index into the enum table. Type 91 is simlar to types
92 & 93: it stores an enum table index in its struct type.

Type 86 is a 2-valued type. The first value is the value of the enum (an
integer between 0 and n). The second value seems to be either 0 or -1,
depending on whether EnumType::Parse was able to produce a valid enum
value.

It is possible that type 86 is actually some kind of generic maybe-error
type that only happens to be used by the enum code. But that doesn't
explain why it is paired with type 91 and not type 92.
2020-01-15 12:59:41 -08:00
Nunuhara Cabbage 32bee0c242 aindump: print array types properly
Print the new v11+ array types properly. Also, print the array rank for
old array types.

The code for reading v11+ ain data is simplified a lot here as well.
2020-01-14 20:43:10 -08:00
Nunuhara Cabbage 6b34660e18 aindump: ain v8+ improvements
I've figured out what most of the extra fields are for. Mostly they are
for:

* a new array type, in which the contained value type is stored in the
  variable object rather than encoded in the type number
* argument initvals (I guess the VM is now responsible for these?)
* interfaces
2020-01-12 21:50:17 -08:00
Nunuhara Cabbage 70a8b9d136 aindump: correct argument types, all syscalls
Use the correct argument types for all instructions, with the exception
of SH_REF_LOCAL_ASSIGN_STRUCTREF2 which I could find an example of.

List all system calls.
2020-01-11 15:05:45 -08:00
Nunuhara Cabbage 8c226ab535 aindump: support code dump up to ain v12 (Rance X)
v11 ain files have 3 new instructions, and 3 modified instructions. It
looks like they decided to break compatibility with this release by
adding arguments to some instructions.

v12 adds one instruction.
2020-01-10 13:38:19 -08:00
Nunuhara Cabbage 302598ace2 aindump: add decrypt mode
Add -d,--decrypt option to dump decrypted ain file (for reverse
engineering).
2020-01-10 12:28:44 -08:00