Commit graph

430 commits

Author SHA1 Message Date
water111 638bf1d3d9
[gltf] Support either u16 or float for colors (#3322)
It seems like this depends on the version of blender, so we should
support both.
2024-01-21 11:03:26 -05:00
Hat Kid 2bb1d53752
custom levels: cell-info and buzzer-info lumps (#3324)
Adds two new lump types: `cell-info` and `buzzer-info`.

`cell-info` takes a `game-task` enum value and defines an `eco-info`
lump for power cells.

`buzzer-info` takes a `game-task` enum value and an integer and
automatically calculates the required value for the buzzer task with the
formula `task + buzzer * (1 << 16)`.
2024-01-21 03:49:55 +01:00
Hat Kid b06d63ba83
custom levels: sort actors by aid and check for duplicates (#3315)
When giving entities custom actor IDs in your level JSON, it is possible
to break entity lookups by actor ID if the actors are not sorted by ID
because `entity-by-aid` expects them to be in order.

This sorts the actor list by ID before generating the level file and
also checks for any duplicates.
2024-01-18 10:29:30 +01:00
water111 4f537d4a71
[jak3] Set up ckernel (#3308)
This sets up the C Kernel for Jak 3, and makes it possible to build and
load code built with `goalc --jak3`.

There's not too much interesting here, other than they switched to a
system where symbol IDs (unique numbers less than 2^14) are generated at
compile time, and those get included in the object file itself.

This is kind of annoying, since it means all tools that produce a GOAL
object file need to work together to assign unique symbol IDs. And since
the symbol IDs can't conflict, and are only a number between 0 and 2^14,
you can't just hash and hope for no collisions.

We work around this by ignoring the IDs and re-assigning our own. I
think this is very similar to what the C Kernel did on early builds of
Jak 3 which supported loading old format level files, which didn't have
the IDs included.

As far as I can tell, this shouldn't cause any problems. It defeats all
of their fancy tricks to save memory by not storing the symbol string,
but we don't care.
2024-01-16 19:24:02 -05:00
jabermony 07427799a6
Jak3 Build Environment (#3098)
This sets out the bones of a Jak 3 build, many things are stubbed out,
guessed, or copied from Jak 2 but it should at least be good enough to:
run `task set-game-jak3`
launch the repl
run builds from the repl

build outputs themselves are untested but the build itself runs without
errors

---------

Co-authored-by: Tyler Wilding <xtvaser@gmail.com>
2024-01-15 20:37:16 -05:00
Tyler Wilding 637b043293
deps: update zydis to latest commit (#3306)
Updates Zydis to it's latest commit, this should fix building the
project on intel macs with a more recent version of macOS. This likely
needs some sanity checks that the debugger stuff still works as
expected.
2024-01-15 16:56:14 -05:00
Hat Kid 619f39d3b7
custom levels: enum lump support (#3305)
This adds support for using enums in lumps using the new lump types
`enum-int32` and `enum-uint32`. Also adds these other new lump types:

- `water-height` (takes 3 meter floats, an enum and another optional
meter float)
- `eco-info` (takes an enum and an int)
- `vector3m` (3 meter floats + `w` set to 1.0)
2024-01-15 12:46:42 +01:00
Matt Dallmeyer 2071c98b55
Fix cases of string formatting with non string literals (#3304)
The logger used in `goalc` tries to print an already-formatted string
`message` using `fmt::print(message);` Usually this doesn't cause
problems, but if you try to print, for example, an exception that has
special characters (notably `{`) it will try to do another round of
formatting/replacements, despite not having any args to replace with,
which ends up throwing another exception. This is why errors when
parsing custom level JSON cause the REPL to exit.

I've hopefully identified all the various instances of this across the
codebase
2024-01-14 12:02:08 +00:00
EvelynTSMG 12118e57cb
Impr: Make mesh extract compatible with gLTF 2.0 (and Blender 4.0) (#3268)
:3
2024-01-01 16:30:48 -05:00
ManDude cd68cb671e
deftype and defmethod syntax major changes (#3094)
Major change to how `deftype` shows up in our code:
- the decompiler will no longer emit the `offset-assert`,
`method-count-assert`, `size-assert` and `flag-assert` parameters. There
are extremely few cases where having this in the decompiled code is
helpful, as the types there come from `all-types` which already has
those parameters. This also doesn't break type consistency because:
  - the asserts aren't compared.
- the first step of the test uses `all-types`, which has the asserts,
which will throw an error if they're bad.
- the decompiler won't emit the `heap-base` parameter unless necessary
now.
- the decompiler will try its hardest to turn a fixed-offset field into
an `overlay-at` field. It falls back to the old offset if all else
fails.
- `overlay-at` now supports field "dereferencing" to specify the offset
that's within a field that's a structure, e.g.:
```lisp
(deftype foobar (structure)
  ((vec    vector  :inline)
   (flags  int32   :overlay-at (-> vec w))
   )
  )
```
in this structure, the offset of `flags` will be 12 because that is the
final offset of `vec`'s `w` field within this structure.
- **removed ID from all method declarations.** IDs are only ever
automatically assigned now. Fixes #3068.
- added an `:overlay` parameter to method declarations, in order to
declare a new method that goes on top of a previously-defined method.
Syntax is `:overlay <method-name>`. Please do not ever use this.
- added `state-methods` list parameter. This lets you quickly specify a
list of states to be put in the method table. Same syntax as the
`states` list parameter. The decompiler will try to put as many states
in this as it can without messing with the method ID order.

Also changes `defmethod` to make the first type definition (before the
arguments) optional. The type can now be inferred from the first
argument. Fixes #3093.

---------

Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
2023-10-30 03:20:02 +00:00
ManDude 09536c68ac
[compiler] asm-only disasm output + fix spacing bug (#3104) 2023-10-29 10:16:14 +00:00
Hat Kid c7c615a043
custom levels: refactor level building code and jak 2 support (#3090)
Co-authored-by: water <awaterford111445@gmail.com>
2023-10-21 06:07:43 +02:00
Hat Kid e6b73f1058
custom levels: support for packing textures (#3089) 2023-10-15 16:36:14 +02:00
water111 395c98db19
[goalc] Cleaned up speedups (#3066)
Started at 349,880,038 allocations and 42s

- Switched to making `Symbol` in GOOS be a "fixed type", just a wrapper
around a `const char*` pointing to the string in the symbol table. This
is a step toward making a lot of things better, but by itself not a huge
improvement. Some things may be worse due to more temp `std::string`
allocations, but one day all these can be removed. On linux it saved
allocations (347,685,429), and saved a second or two (41 s).
- cache `#t` and `#f` in interpreter, better lookup for special
forms/builtins (hashtable of pointers instead of strings, vector for the
small special form list). Dropped time to 38s.
- special-case in quasiquote when splicing is the last thing in a list.
Allocation dropped to 340,603,082
- custom hash table for environment lookups (lexical vars). Dropped to
36s and 314,637,194
- less allocation in `read_list` 311,613,616. Time about the same.
- `let` and `let*` in Interpreter.cpp 191,988,083, time down to 28s.
2023-10-07 10:48:17 -04:00
water111 0e31a9c407
[decompiler] Handle find-parent-method (#3018)
This change adds a few new features:
- Decompiler automatically knows the type of `find-parent-method` use in
jak 1 and jak2 when used in a method or virtual state handler.
- Decompiler inserts a call to `call-parent-method` or
`find-parent-state`
- Removed most casts related to these functions

There are still a few minor issues around this:
- There are still some casts needed when using `post` methods, as `post`
is just a `function`, and needs a cast to `(function none)` or similar.
It didn't seem easy to change the type of `post`, so I'm not going to
worry about it for this PR. It only shows up in like 3 places in jak 2.
(and 0 in jak 1)
- If "call the handler if it's not #f" logic should probably be another
macro.

Fixes #805
2023-09-30 11:06:09 -04:00
ManDude 170cbd7e6c
misc low hanging fruit fixes (#3034)
Fixes #2235 
Fixes #2236 
Fixes #2963 
Fixes #3027
2023-09-27 00:59:07 +01:00
ManDude 9b60afe6e6
[compiler] fix compile_condition not attempting macro expansion (#3030)
Ancient bug! Resulted in a 1%-2% decrease in code object file size (and
more importantly the asm is more readable).

Fixes #3029
2023-09-25 23:49:12 +01:00
ManDude 61c4fc4b91
[jak2] fully implement collide mesh renderer (#3010)
Fixes #2983
2023-09-22 15:50:16 +01:00
ManDude fe491c2b5e
[opengoal] make none a child of object (#3001)
Previously, `object` and `none` were both top-level types. This made
decompilation rather messy as they have no LCA and resulted in a lot of
variables coming out as type `none` which is very very wrong and
additionally there were plenty of casts to `object`. This changes it so
`none` becomes a child of `object` (it is still represented by
`NullType` which remains unusable in compilation).

This change makes `object` the sole top-level type, and the type that
can represent *any* GOAL object. I believe this matches the original
GOAL built-in type structure. A function that has a return type of
`object` can now return an integer or a `none` at the same time.
However, keep in mind that the return value of `(none)` is still
undefined, just as before. This also makes a cast to `object`
meaningless in 90% of the situations it showed up in (as every single
thing is already an `object`) and the decompiler will no longer emit
them. Casts to `none` are also reduced. Yay!

Additionally, state handlers also don't get the final `(none)` printed
out anymore. The return type of a state handler is completely
meaningless outside the event handler (which is return type `object`
anyway) so there are no limitations on what the last form needs to be. I
did this instead of making them return `object` to trick the decompiler
into not trying to output a variable to be used as a return value
(internally, in the decompiler they still have return type `none`, but
they have `object` elsewhere).

Fixes #1703 
Fixes #830 
Fixes #928
2023-09-22 10:54:49 +01:00
Hat Kid bfb03d4934
goalc: add macro-expand form (#3000) 2023-09-17 22:55:25 +02:00
water111 74250a22f7
Save entities to JSON, and make custom level building a little faster (#2973)
This will create a folder like `decompiler_out/jak1/entities` and save a
JSON file per level with all the actors.

Also, it should hopefully make custom level building a little faster.
2023-09-09 17:06:39 -04:00
Tyler Wilding 07d97bce8c
goalc: use iso_data build_info to inform custom level build process (#2959) 2023-09-03 18:17:35 -04:00
ManDude 6e8b0e57c7
[extractor] fix territory being set to wrong value (#2946)
Also fixes a minor issue where the JP sound bank wouldn't work (Jak 1).

Fixes #2793
2023-08-30 18:36:10 +01:00
ManDude 8bb5fa7f04
various subtitle editor fixes (#2941)
- fix speaker names and time frames being uneditable in Jak 1
- added toggle to auto-selected a newly created scene as current
- changed the subtitle summary format slightly.
- current scene's name now appears in the UI
2023-08-28 17:51:09 +01:00
Hat Kid dc7c71c07d
custom levels: add support for packing models and textures into the FR3 file (#2936) 2023-08-27 22:34:46 +02:00
water111 3b29da919b
[jak 2] Clouds V2, Clean up texture animator (#2921)
Some general improvements for the texture animator:
- Clouds are special cased, saving about 1 ms per frame
- Adjusting the amount of clouds now actually works.
- Fixed an issue with the brightness of clouds, and the way that they
fade out around the edges.
2023-08-19 12:50:59 -04:00
water111 7abfeb4aa7
[jak1] Fix texture-related custom level crash (#2898)
Force FR3 file name for custom levels to be uppercase, fixes the crash
described in
https://github.com/open-goal/jak-project/issues/2534
and 
https://github.com/open-goal/jak-project/issues/2897
2023-08-13 15:22:40 -04:00
Tyler Wilding a06a6c6416
cleanup our cmake and build warnings (#2876) 2023-08-08 20:53:16 -04:00
Hat Kid 6061f39728
custom levels: fix crash when more than one ambient is present (#2891) 2023-08-08 20:24:13 +02:00
Tyler Wilding 5d7aa7cea1
log: rotate log files with timestamps and add flag to disable ANSI colors (#2886)
Rotates the log files with a timestamp instead of copying all files and
incrementing an integer. Increases the amount of info you have when
looking at user's log files (ie. when looking at all the files, the file
creation dates are accurate).


![image](https://github.com/open-goal/jak-project/assets/13153231/61bcdf51-f0f6-4eee-b1e5-140aede5d19e)

Also simplifies the API for setting the log file, and `gk` logs are now
game specific with `jak1` or `jak2`. Which should be useful going
forward.

Lastly, added a flag to all CLIs to disable ansi colors for people that
want to do so. Though at the same time, there is finally a workaround in
jenkins to fix ANSI colors in the truncated log view -- so I'm not sure
why anyone would want to get rid of the color information. You can even
setup text editors to display the color info making log parsing much
easier. Fixes #1917

---------

Co-authored-by: ManDude <7569514+ManDude@users.noreply.github.com>
2023-08-08 17:59:37 +01:00
Tyler Wilding e0bc7ce732
Get the project compiling on Apple Silicon macOS natively (arm64) (#2827)
I havn't tested it yet, but I can almost guarantee that atleast `goalc`
will not work in the slightest!

But the project is atleast fully compiling. My hope is to start
translating some AVX to NEON next / get `goalc` working...eventually.
2023-07-16 11:13:48 -04:00
Tyler Wilding c87db7e670
i18n: subtitle code cleanup and update new subtitle JSON files to be compatible with Crowdin (#2802)
The main thing that was done here was to slightly modify the new
subtitle-v2 JSON schema to be more similar to the existing one so that
it can properly be used in Crowdin.

Draft while I double-check the diff myself

Along the way the following was also done (among other things):
- got rid of as much duplication as was feasible in the serialization
and editor code
- separated the text serialization code from the subtitle code for
better organization
- simplified "base language" in the editor. The new subtitle format has
built-in support for defining a base language so the editor doesn't have
to be used as a crutch. Also, cutscenes only defined in the base come
first in the list now as that is generally the order you'd work from
(what you havn't done first)
- got rid of the GOAL subtitle format code completely
- switched jak 2 text translations to the JSON format as well
- found a few mistakes in the jak 1 subtitle metadata files
- added a couple minor features to the editor
- consolidate and removed complexity, ie. recently all jak 1 hints were
forced to the `named` type, so I got rid of the two types as there isn't
a need anymore.
- removed subtitle editor groups for jak 1, the only reason they existed
was so when the GOAL file was manually written out they were somewhat
organized, the editor has a decent filter control, there's no need for
them.
- removed the GOAL -> JSON python script helper, it's been a month or so
and no one has come forward with existing translations that they need
help with migrating. If they do need it, the script will be in the git
history.

I did some reasonably through testing in Jak1/Jak 2 and everything
seemed to work. But more testing is always a good idea.

---------

Co-authored-by: ManDude <7569514+ManDude@users.noreply.github.com>
2023-07-09 02:53:39 +01:00
ManDude b3e3f9379e
fix some jak 1 hint subtitles not showing up (#2782)
There is one instance of the same hint being played for different IDs
which was breaking things.
2023-06-28 14:13:47 +01:00
ManDude f8d4489361
fix more orb softlocks (#2767)
Fixes orb softlocks during races and other side missions.

The side mission tasks will now not count as completed until the
precursor orb has been picked up.

Races will not let you advance (or even pause the game) until the
precursor orb has been picked up.
2023-06-27 22:02:21 +01:00
Tyler Wilding 10934f6746
d/j2: Some work on the SQL editors (#2771) 2023-06-25 16:51:46 -04:00
water111 2fc943977f
[jak2] GOAL side texture animation stuff (#2766)
It turns out we didn't decompile any of this stuff yet.
2023-06-24 10:11:47 -04:00
water111 ad5cec1bb4
[jak2] Floating point blerc (#2715)
This moves the blerc math from mips2c to the Merc2 renderer, and uses
floats instead.

We could potentially do this on the GPU, which would be even faster, but
this isn't that slow in the first place.
2023-06-11 12:35:08 -04:00
ManDude 18ddd1613c
Jak 2 pc subtitle support (#2672)
Adds support for adding custom subtitles to Jak 2 audio. Comes with a
new editor for the new system and format. Compared to the Jak 1 system,
this is much simpler to make an editor for.

Comes with a few subtitles already made as an example.
Cutscenes are not officially supported but you can technically subtitle
those with editor, so please don't right now.

This new system supports multiple subtitles playing at once (even from a
single source!) and will smartly push the subtitles up if there's a
message already playing:

![image](https://github.com/open-goal/jak-project/assets/7569514/033e6374-a05a-4c31-b029-51868153a932)

![image](https://github.com/open-goal/jak-project/assets/7569514/5298aa6d-a183-446e-bdb6-61c4682df917)

Unlike in Jak 1, it will not hide the bottom HUD when subtitles are
active:

![image](https://github.com/open-goal/jak-project/assets/7569514/d466bfc0-55d0-4689-a6e1-b7784b9fff59)

Sadly this leaves us with not much space for the subtitle region (and
the subtitles are shrunk when the minimap is enabled) but when you have
guards and citizens talking all the time, hiding the HUD every time
anyone spoke would get really frustrating.

The subtitle speaker is also color-coded now, because I thought that
would be fun to do.

TODO:
- [x] proper cutscene support.
- [x] merge mode for cutscenes so we don't have to rewrite the script?

---------

Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
2023-06-08 01:04:16 +01:00
Tyler Wilding 057ae361bf
LSP: OpenGOAL Feature Support - Part 1 (#2668) 2023-05-21 17:24:23 -04:00
water111 d5951c2b11
[jak 2] Fix possible stereo desync in overlord (#2663)
Normally, when they allocate a VagCmd, they do a bunch of stuff to clear
all the status bits and reset things
in particular the InitVAGCmd function does a lot


![image](https://github.com/open-goal/jak-project/assets/48171810/9b355020-ad37-496c-9438-2f8d34f24e0a)

but for the stereo command, they do a lot less:

![image](https://github.com/open-goal/jak-project/assets/48171810/12a36712-0e68-4377-a6be-3bde82c2aa15)

Which means that the new_stereo_command can just have random status bits
left over from whatever the last user had.
we seem to end up in a state where byte21 is set, and this causes
everything else to be wrong and off-by-one dma transfer. My guess is
that the original game avoided this bug due to lucky timing that I don't
understand.

I think the fix of just clearing byte21 is ok because there's no way
that the old value of the byte is useful after the command is
repurposed.
2023-05-19 21:17:11 -04:00
Tyler Wilding 288c093913
i18n: Create a JSON subtitle format for translating via Crowdin (#2644) 2023-05-18 20:54:59 -04:00
water111 ef23fecd90
[goalc] default to non-immediate lambdas if not requested (#2604)
This fixes a long time issue with `lambda`. The `lambda` is a bit
overloaded in OpenGOAL: it's used in the implementation of `let`, and
also to define local anonymous functions.

```
(defmacro let (bindings &rest body)
  `((lambda :inline #t ,(apply first bindings) ,@body)
    ,@(apply second bindings)))
```

```
(defmacro defun (name bindings &rest body)
  (let ((docstring ""))
    (when (and (> (length body) 1) (string? (first body)))
      (set! docstring (first body))
      (set! body (cdr body)))
    `(define ,name ,docstring (lambda :name ,name ,bindings ,@body))))
```

In the first case of a `let`, a `return` from inside the `let` should
return from the functioning containing the `let`, not the scope of the
`lambda`. In the second case, we should return from the lambda. The way
we told the different between these cases was if the `lambda` was used
"immeidately", in the head of an expression (like it would be for the
`let` macro). But, this falsely triggers when an anonymous function is
used immediately: eg
```
((lambda () (return #f)))
```
should generate and call a real x86 function that returns immediately.

This should fix some death/mission failed stuff in jak 2.
2023-04-30 19:00:27 -04:00
Tyler Wilding 6d52e002b9
i18n: init translation files that can be used by crowdin (#1760) 2023-04-30 17:22:56 -04:00
ManDude d67b95c68f
allow quoting :key symbols + further optimize defpart (#2592)
This should hopefully improve build times in general, especially for
files with `defpart`.
2023-04-30 02:46:14 +01:00
ManDude 2feb231105
less branches for division + fix divide by zeros (#2585)
Slight change to float divide operations (again). Now it only turns into
inverse multiplication if the float is a power of 2 (positive or
negative). Non-zero immediate divisors will be compiled as regular float
divisions but will forgo the extra branches and checks for divide by
zero.

Also fixes #2584
2023-04-29 21:10:51 +01:00
ManDude 0ce5835818
Create a new format for particle definitions (defpart) (#2572)
Updates the decompiler for the new format and there's new macros. This
new format should be easier to read/parse.

Also rewrote `sp-init-fields!` (both jak 1 and 2) from assembly to GOAL.

Hopefully I did not miss any regressions in Jak 1/2 while updating the
files, it's a lot.
2023-04-29 11:01:47 -04:00
Tyler Wilding a264b6539b
game: Remove temporary CLI arg shim in gk (#2532) 2023-04-22 14:13:57 -04:00
Tyler Wilding 10ac78200b
repl: add gameVersionFolder to repl-config for running the non-default version (#2463)
Adds a decent way to customize the folders the project file expects the
iso data and decompiler data to be in. When you run any version other
than the default, for example Jak 1 PAL, it uses the `gameName`
decompiler config to consume and output it's results.

However the project file will assume `jak1` unless you hard-code it
differently -- basically, it needs to be explicitly told just the
decompiler is told what version to use.

We now have a per-user REPL Config json file, so that can be used to
override the default `jak1` behaviour.

Fixes #1993
2023-04-11 17:57:20 -04:00
ManDude 6f1cb2a0a9
fix repl buffer overrun + use a different port for each game version (#2449)
Fixes #2313
2023-04-02 05:57:21 +01:00
water111 56eeb20e4c
[goalc] fix bug in subtraction (#2399)
fixes the turrets pointing down in fortress dump mission

Co-authored-by: ManDude <7569514+ManDude@users.noreply.github.com>
2023-03-23 18:09:27 +00:00