Author Topic: Kajar Engine - An open source engine for Chrono Trigger  (Read 7008 times)

Schala Zeal

  • Radical Dreamer (+2000)
  • *
  • Posts: 2147
  • 7th Elemental Innate, and vtuber
    • View Profile
Kajar Engine - An open source engine for Chrono Trigger
« on: July 27, 2023, 11:57:51 am »
So for the past few months, I've been coding a project I've dubbed the Kajar Engine. What this is is not a remake of Chrono Trigger itself, but its engine. If any of you know what GZDoom, Brutal Doom or OpenRCT2 are, that saves me an explanation. It's a free, from scratch, open source reimplementation of the Chrono Trigger engine. I wanted to wait til I had hit a few working milestones with it before I officially announced it. Last night I just got it to extract and import the Steam port's game data. My goals for this project is to make this the most optimal way to play Chrono Trigger, while making it easy to mod.

Project page: https://github.com/Schala/KajarEngine

Legal considerations:
- As stated, the engine will need the assets from a retail copy of the game to import and run.
- The Steam and mobile retail ports use Blowfish encryption for some files. While the "initialisation tables" are public domain and in the engine's importer, the encryption key is proprietary, and embedded within the Steam/mobile binary executable. The Dolphin project was denied on Steam because it had copied the Wii decryption key from the system, making it legally ambiguous. To avoid the same fate, the engine looks within the EXE at a hardcoded offset, reading 64 bytes from said offset. The downside is that this will likely need to be updated with any future patches to Chrono Trigger's Steam or mobile ports.

A list of details:
- Coded in Rust to make this as bug free as possible and not make debugging a pain in the butt
- Has an importer that extracts the game data from a legally purchased copy of Chrono Trigger. Currently, only the Steam port as it is the easiest, but more ports are planned to support, thanks to the plethora of modding info the compendium has
- As this is open sourced under the GPLv3 license, this will make Chrono Trigger 64-bit capable and allow the community to keep it up to date and add new stuff. As per the licensing terms, it allows you to modify the code as you wish, but if you plan to share your work, you must also make the code available for your entire project.
- Enemy AI and other functional code will be converted into Lua scripts upon import. The modding capabilities themselves will use Lua for AI, story driven code, etc. Lua is the scripting language used by WoW addons and Roblox, to name a few examples, and as a coder, I love its embedding efficiency.
- For major modding, I want to look into developing a plugin API. This will be coded in Rust, but it can interop with C too, for those who find it easier.
- The game will use the Bevy engine to run, as I find it the easiest, powerful, and most minimal to pick up.
- The Kajar Engine is being coded to surpass the hard-coded limits imposed by Chrono Trigger. With modding, putting in new character slots, for example, will be a breeze.
- As the game data is imported, special hash table files will be created. This will allow integrity checks between the vanilla game data and modded content. If two or more mods modify the same content, an error will occur.

What's done:
- resources.bin extraction
- TIM to PNG conversion (actually for possible Cross support, but I already coded something years ago, so this was easy)
- DRP import
- CPT import
- TBT import
« Last Edit: August 28, 2023, 03:37:33 pm by Schala Zeal »

Boo the Gentleman Caller

  • Guru of Life Emeritus
  • Hero of Time (+5000)
  • *
  • Posts: 5299
    • View Profile
Re: OpenCT - An open source engine for Chrono Trigger
« Reply #1 on: July 28, 2023, 06:52:49 pm »
This is very cool. I'm not a software engineer / developer, but I do work in the industry and know that this is no small feat. I can't wait to see how it develops, Schala!

Schala Zeal

  • Radical Dreamer (+2000)
  • *
  • Posts: 2147
  • 7th Elemental Innate, and vtuber
    • View Profile
Re: OpenCT - An open source engine for Chrono Trigger
« Reply #2 on: July 28, 2023, 07:22:48 pm »
I just found out some of the files were encrypted with a Blowfish block cipher. The whole Blowfish initialisation table is in the EXE. I just found the offset which has the decryption key, so that's going to help write the importer. Once I get the importer done, I can start on the actual engine.

Nangbaby

  • Porrean (+50)
  • *
  • Posts: 91
  • Frankenspriter at Large
    • View Profile
Re: OpenCT - An open source engine for Chrono Trigger
« Reply #3 on: August 01, 2023, 12:37:09 am »
This means after all these years, we're going to finally get a real, adaptable Chrono Engine.  :D

If so, thank you. If not, thank you for making the attempt.

I do have a question.  Is this engine going to stick strictly with the limits of Chrono Trigger (magic system, number of tech combinations, party size, etc.), or will it offer a some flexibility in terms of expandable content?


Edit: I read what this actually is now.  I misunderstood, but still, thanks.
« Last Edit: August 03, 2023, 05:59:15 pm by Nangbaby »

Schala Zeal

  • Radical Dreamer (+2000)
  • *
  • Posts: 2147
  • 7th Elemental Innate, and vtuber
    • View Profile
Re: Kajar Engine - An open source engine for Chrono Trigger
« Reply #4 on: August 06, 2023, 02:53:27 pm »
I've renamed OpenCT to the Kajar Engine first because OpenCT and OpenChrono are already used, and second, to possibly put in Cross support eventually.

TheMage

  • Artist of Termina
  • Time Traveler (+800)
  • *
  • Posts: 876
  • Dreaming through time.
    • View Profile
Re: Kajar Engine - An open source engine for Chrono Trigger
« Reply #5 on: August 18, 2023, 07:27:53 pm »
Damn this is impressive!! Amazing work Schala!

Schala Zeal

  • Radical Dreamer (+2000)
  • *
  • Posts: 2147
  • 7th Elemental Innate, and vtuber
    • View Profile
Re: Kajar Engine - An open source engine for Chrono Trigger
« Reply #6 on: August 20, 2023, 03:59:33 pm »
Thanks Mage! I went ahead and updated the OP with a (growing?) list of legal considerations as well.

Daedalus007

  • Iokan (+1)
  • *
  • Posts: 4
    • View Profile
Re: Kajar Engine - An open source engine for Chrono Trigger
« Reply #7 on: August 24, 2023, 05:31:44 pm »
*snip*

My goodness, getting back into forums after so many years of exclusively using Discord is a blast from the past, lmao.  Your URL linking is kinda jank/oldschool.  Some of these 'insert' icons are from Windows95 era (yes, I remember) and Internet Explorer 5 or 6 specifically.

---

As a modder for Chrono Trigger (a prominent bugfix patch among others), I'd like to offer a few considerations for modding and making things easier down the line.

-Modding should be built-in and easy to download; for a reference implementation look at what 'Battle for Wesnoth' does for their modding community.  Within the game itself is a full implementation that lists mods, allows for sorting/searching, and downloads/installs/restarts as necessary without requiring technical knowledge from the end-user.

-Lua is fantastic, though it has some significant limitations we need to keep in mind (no ability to create 'switches'; we have to use if/then/else (ITE) statements and nested within nested ITE statements makes code difficult to debug and patch up later on.  If you can work around this limitation NOW in the engine-development stage (via plugin or in the core engine itself) that will be amazing!

-GPLv3 is fantastic also and thanks for being liberal/freedom with such a license, however keep in mind this allows anyone to commercially exploit the work as well.  We've seen what happens with the flood of 'retro hardware' that ends up just being 'emulator boxes'.  We also have seen what happens when open source community software gets abused.

I'd strongly request/recommend that a future update be a hard-fork that changes the license to Creative Commons Attribution Non-Commercial ShareAlike.  That is much more difficult to abuse financially since it says 'Non-Commercial' as a prominent easily-seen point right there in the license name.  This would upset some Linux-based OS purists but I don't feel that catering to their niche needs is in the best interest of this project or community.  If they don't wanna put something in their repository that is 'non-commercial' license then so be it.  There's a full CC licenses list here for reference.

nevermind on this

-Finally for those who are 'purists' it may be useful to have a 'purist' mode that adheres to the original hardware limitations (be it SNES or later, but probably just SNES).

Also Hi Mauron ;)

Schala Zeal

  • Radical Dreamer (+2000)
  • *
  • Posts: 2147
  • 7th Elemental Innate, and vtuber
    • View Profile
Re: Kajar Engine - An open source engine for Chrono Trigger
« Reply #8 on: August 28, 2023, 01:58:39 pm »
What do you mean nevermind the licensing? Also, if not Lua, what scripting language would you recommend? I haven't done anything scripting wise yet, so there's still time for suggestions.
« Last Edit: August 28, 2023, 03:36:52 pm by Schala Zeal »

Zakyrus

  • Entity
  • Magical Dreamer (+1250)
  • *
  • Posts: 1358
  • "Bouncy, bouncy, bouncy... --!!"
    • View Profile
Re: Kajar Engine - An open source engine for Chrono Trigger
« Reply #9 on: September 11, 2023, 01:27:47 pm »
Don't worry about liscensing, you could always 'represent' your "software development kit"(aka OpenSource Engine) as "'ART' for the sake of Art" because it is, therefore, there are several liscensing available for free (as intellectual property you REALLY DONT need to define)--HOWEVER, there are a few available anyways such as "GNU General Public License" etc.

Hope that helps.
;)

~Z

froodo

  • Porrean (+50)
  • *
  • Posts: 76
    • View Profile
Re: Kajar Engine - An open source engine for Chrono Trigger
« Reply #10 on: July 05, 2024, 01:03:58 am »
Just returned to the forums after a long time, and oh my god! So much developements!

I wish we can be able to extract the assets directly from SNES/PS1/NDS ROM/ISOs instead of that botched PC release. Would be superb!

Schala Zeal

  • Radical Dreamer (+2000)
  • *
  • Posts: 2147
  • 7th Elemental Innate, and vtuber
    • View Profile
Re: Kajar Engine - An open source engine for Chrono Trigger
« Reply #11 on: July 16, 2024, 05:56:16 pm »
That's the eventual plan. I mean, thanks to the memory mapping in the wiki, that might be doable soon.

Kiloku

  • Iokan (+1)
  • *
  • Posts: 4
    • View Profile
Re: Kajar Engine - An open source engine for Chrono Trigger
« Reply #12 on: November 03, 2024, 07:01:10 pm »
I have some info that might be useful for importing game data.

I'm figuring out how the Map files work, as a potential first step to create a map editor for the Steam version.

In Game/world/Map, each Map_000X.dat file is composed of two layers that are 6144 bytes long, for a total 12288 bytes.
 
Each layer can be organized into a 96x64 grid which represents the graphical tile on the related worldchip PNG file (in Game/world).

So here's an example of worldchip_0_4_1.png, annotated with the tile hex index:


Here's Map_0000.dat in a Hex viewer (scrolled down to the beginning of the bottom layer and configured to use 96-byte long columns):


And finally, here's a screenshot of northern Truce in the in-game map:


Notice that the many CD on the top-left of the Hex editor, each matches a deep ocean tile, which is CD in the worldchip image as well.
Additionally, look at this section that goes from B0 to B5 (with C0 to C4 right below), these are the Guardia Castle tiles:


I hope you can make use of this. I'm thinking of writing a map editor myself, but wanted to share my findings too.
« Last Edit: November 03, 2024, 07:02:28 pm by Kiloku »