Jump to content


Member Since 23 May 2016
Offline Last Active Yesterday, 11:29 PM

Posts I've Made

In Topic: [WIP] (b1.0.0) KOTORPatcher - TSLPatcher-like app for Android

Yesterday, 11:29 PM

Hmm it seems like it overrides danm files as well instead of skipping them?

You mean this mod? Unfortunately, this app doesn't yet support editing GFF files (such as UTI files), or .mod files, so that is likely the issue. Is your issue the model (which I think should work?) or the fabricator on Dantooine?
EDIT: Also, currently, if there are conflicts the app overrides them. I'm planning next update to add an option.

In Topic: [WIP] (b1.0.0) KOTORPatcher - TSLPatcher-like app for Android

15 January 2018 - 06:27 AM

Latest update out! Thanks a ton peedeeboy for the code to read and write the 2da files!
b1.0.0 {13}

  • REQUIRES REINSTALL - Changed signing key (I'm sorry, I forgot the old one)
  • Not doing debug builds any more
  + 2DA support (thanks a ton @peedeeboy!)
  + Option to create a 2DA from scratch (test)
  + Do not install music or launcher (not supported by Android KOTOR)

  • Log now updates while in progress
  • App no longer freezes when installing mods
Next, I will be working on a nicer UI, and then namespaces and info.rtf (both of which will require UI changes anyway, so I'm taking advantage of that).

In Topic: Editing offsets in binary 2DAs

11 January 2018 - 12:56 AM

When I wrote those classes, it a quick and dirty solution whilst I was still trying to figure the .2da file type out properly.  I didn't really think about the GUI - conceptually, I needed a two-dimensional array, so I used Object[][].  Also, one can construct a JTable by passing it a two dimensional Array.  Using Collections (such as ArrayList) one has to extend AbstractTableModel and write implement some of the methods (such as how to set data in a particular cell) oneself.
And as arrays take up consecutive space in the heap memory, its a pain to add rows in the middle...
Of course - you might not want to add that functionality, as for editing the existing .2da files, I believe its generally considered best to leave the existing order of rows as is, and add any new rows to the end of the file.
But if you want people to be able to create .2da files from scratch - Collections will probably be the way to go
EDIT: I also stored row headings in a seprate list, as that is conceptually how they are stored in a 2da file.  But in the Netbeans plugin I'm working on at the moment, I will probably add them into the first column of the table model, so the user can edit them as if they were part of the data (a la the way KOTORTool does it).  Again - stylistic choice based on GUI!

Its a stylistic choice on your part - but most programmers think that functions/methods should have one simple purpose.  It makes code eaiser to read / maintain in the long run over monolithic scripts.  E.g. in this instance, you might have a public write() method that accepts the table model, headers etc.  But that method will then call several private methods for each stage writeHeader() writeOffsets() writeData() etc.
This means your write() method reads more like a recipe, and you can skip to the other methods as you need.  Code that reads like a recipe is easy to maintain - so the theory goes.

Its a stylistic choice against for consistency in this script.  I copied the hex for "2DA V2.b" from opening actions.2sa in a hex editor, (because I couldn't be bothered to look the characters up in an ASCII table) so everywhere else I referred to a byte I used the hex code, rather than an integer too.
Again, I could have stored "2DA V2.b" as a string, and converted it to bytes and written it out, but it was quick and easy to store the bytes as a constant because they would always be the same writing any binary 2da....
There's no write or wrong answer there, only preference!
Good luck with the project!  :ice:

OK thanks. Your code functions 100% fine, I wonder what was wrong with mine, since difficultyopt.2da worked.
So I should change the data array in your TwoDA class to a List of Lists of Strings?
I do actually currently have a test option that allows creating 2das, but it uses newline and comma delimiters rather than a table, at least for now.

In Topic: Editing offsets in binary 2DAs

10 January 2018 - 11:46 PM

Here's a dirty big monolithic Java script to write a binary 2da file I just bashed together. It is based on the first three rows of Actions.2da and uses a Map to ensure there is one unique entry for each string in the data section - as ndix UR suggested.

Obviously, you would want to split each part of the process out into a separate function...

There's no real error checking or data validation either (I think spaces/whitespace would need to be stripped from user input?) - and I'm using a List of Lists of Strings for the 2da model - I don't know much about Android UI components, but for most desktop Java GUI components you need to use Collections rather than Arrays for the TableModel if you want to add / remove rows etc.


Here is the resulting file opened in KOTORTool. Hopefully you find this useful :ice:
Thanks, I'll test that. I solved the issue I mentioned, though it still acts up. My code can successfully edit difficultyopt.2da (Impossible difficulty in K1R), but appearance.2da messes up (the 2da opens fine, but characters are invisible, so probably just need to check for issues in the data). That looks really similar to my code, except that I use arrays. I wrote my method to use your TwoDA class, so I'll have to change that.
At least for now, I have no visual editor, it just parses changes.ini, so the GUI doesn't matter yet.
Why would I need to split them? A lot of changes affect other parts, so I'd think it'd be better to rewrite it all, just in case?
EDIT: Also, any reason you used hex codes over numbers (0x00 instead of 0, 0x0A instead of 10, etc)?

In Topic: Editing offsets in binary 2DAs

10 January 2018 - 10:07 PM

Newline in Unix is 10 (0x0A), no?  So, if you are opening a file in a text editor looking for Unix line endings and using a UTF-8/ASCII encoding, every time it finds a 0x0A byte it will interpret that as a new line.
Have you tried using a simple / small file (as per my example) and checking manually in a hex editor?

The offset code works. The issue was with another section. Thanks for the help!