NickHugi / PyKotor

A Python library that can read and modify most file formats used by the game Knights of the Old Republic and its sequel.
GNU Lesser General Public License v3.0
11 stars 3 forks source link

Holocron Toolkit: NSS editor Compile option can write to .rim files even with save to RIM disabled #68

Closed JoeNotCharles closed 5 months ago

JoeNotCharles commented 6 months ago
  1. Make sure the "Allow saving resources to RIM files" setting is turned off.
  2. Open a foo_s.rim file from an installed game.
  3. Open any NCS resource in the .rim. Say it's "a_script".

The NSS editor will open with the filename set to foo_s.rim/a_script.ncs. (Either it'll have the decompiled source of a_script.ncs, or it'll be blank. Doesn't matter either way.)

  1. Paste a completely new script into the editor.
  2. Choose "Compile". (I used nwnnsscomp.exe, haven't tested with the internal compiler.)

The new script will be compiled to an NCS resource and saved over a_script in foo_s.rim, even though "allow saving resources to RIM files" is disabled.

JoeNotCharles commented 6 months ago

I almost have a fix for this, but it needs some cleanup before I commit it.

The root cause is that NSSEditor.compileCurrentScript doesn't go through the save() / build() path, instead it has custom code to write the compiiled script, which doesn't check settings.disableRIMSaving. (Also NSSEditor.build() doesn't work at all for NCS files - it looks like a "raise ValueError" was pasted into the success path by mistake.)

th3w1zard1 commented 6 months ago

Thank you for reporting this. There's a few niche scenarios like this where the toolset isn't properly checking that setting.

JoeNotCharles commented 6 months ago

I tested both the beta release and the PyKotor master branch.

I have a fix at https://github.com/NickHugi/PyKotor/pull/70, but it's a bit wonky. Not sure if it's the correct approach.

On Sun, Mar 10, 2024 at 4:05 PM Benjamin Auquite @.***> wrote:

To clarify is this happening in the beta version or the last DS release version?

— Reply to this email directly, view it on GitHub https://github.com/NickHugi/PyKotor/issues/68#issuecomment-1987347140, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMDPPYQOT3SSJALY6CIAJLYXTDIPAVCNFSM6AAAAABEOPJRDWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBXGM2DOMJUGA . You are receiving this because you authored the thread.Message ID: @.***>

th3w1zard1 commented 6 months ago

It's a good starting point at least. Btw the betas are created from the bleeding-edge branch

th3w1zard1 commented 6 months ago

I'm struggling to reproduce this issue. NSS scripts are compiling fine with that option disabled. Is there any way you can attach errorlog.txt so I can see the stack trace?

EDIT: Sorry I commented this in the wrong place. You mentioned the ValueError was being raised in the incorrect spot. I belive I meant to write this on the PR. Did that come with a stack trace?

JoeNotCharles commented 6 months ago

I'm struggling to reproduce this issue. NSS scripts are compiling fine with that option disabled. Is there any way you can attach errorlog.txt so I can see the stack trace?

EDIT: Sorry I commented this in the wrong place. You mentioned the ValueError was being raised in the incorrect spot. I belive I meant to write this on the PR. Did that come with a stack trace?

Split that out into https://github.com/NickHugi/PyKotor/issues/71

JoeNotCharles commented 5 months ago

I messed up the branches and pull requests in my repo. The most up-to-date fix for this is now at https://github.com/JoeNotCharles/PyKotor/tree/fix_compile_script (which includes the commit from the PR I accidentally deleted, plus another cleanup)