Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Rewrite applying extensions #365

Draft
wants to merge 1 commit into
base: 4.x
Choose a base branch
from

Conversation

cgytrus
Copy link

@cgytrus cgytrus commented Mar 10, 2024

Fixes the currently main 4.x issue

  • disallows installing extensions outside of _init
    • same reason as below, allowing this would require restructuring my code again..
  • removes runtime mod toggling/reloading
    • too complicated for me to implement with the rewrite and ive been told it was unstable anyway
  • fixes preloaded scenes that refer to extended scripts not getting updated
    • if you have a scene that refers to a script, that scene gets preloaded and the script gets extended, the preloaded version of the scene would still refer to the old script, i believe the use of reload instead of new fixes that but i havent actually checked if thats true
  • the rewrite ends up fixing these
  • supersedes fix: non-static func call on InheritanceSorting #363 (already merged anyway)

how this works:

  • collects all extension scripts (no changes here)
  • uses the base script as the original script that will be extended (no changes here either)
  • copies the original script to a temporary directory on disk
    • it seems to be impossible to create a new file in the project otherwise and extends ignores resource cache, which is what take_over_path overrides, it reads only from packs or the file system
  • extends in the extension scripts is patched to instead extend the script previous in the mod hierarchy, down to the copied original file
  • the original script's source is overwritten with the source of the last applied extension
    • take_over_path didnt seem to work for this
    • the hierarchy ends up as mod (overwritten original) > mod > mod > ... > copied original
  • all involved scripts are reloaded in backwards order (starting from copied original, ending with overwritten original)
    • this ensures that all the scripts are up to date with the patches and preloads and whatnot
  • temporary directory together with all the patched extensions and copied original is deleted from disk as theyre now loaded and not needed anymore

i didnt test much, especially with dependencies, but for a simple use case of a couple mods this seems to be working
also please squash when merging lol

current issues:

  • there seems to be an issue where this also ends up hijacking the paths in the debugger too, when you click on an extended script in a stack trace it opens files that were either already deleted from the temp folder or original files that had their source code replaced in runtime

@KANAjetzt KANAjetzt added the 4.x label Mar 10, 2024
@KANAjetzt KANAjetzt added this to the 4.x - 6.2.0 milestone Mar 10, 2024
@KANAjetzt KANAjetzt requested a review from a team March 10, 2024 19:15
@cgytrus cgytrus changed the title Rewrite applying extensions Various 4.x fixes/imporvements Mar 11, 2024
@cgytrus cgytrus closed this Mar 11, 2024
@cgytrus cgytrus deleted the windowkill branch March 11, 2024 19:55
@cgytrus cgytrus restored the windowkill branch March 11, 2024 19:55
@cgytrus cgytrus reopened this Mar 11, 2024
@cgytrus cgytrus changed the title Various 4.x fixes/imporvements Rewrite applying extensions Mar 11, 2024
@KANAjetzt KANAjetzt added bug Something isn't working refactor / cleanup Improves readability or maintainability labels Mar 13, 2024
@KANAjetzt KANAjetzt changed the title Rewrite applying extensions refactor: Rewrite applying extensions Mar 16, 2024
@KANAjetzt KANAjetzt removed the bug Something isn't working label Mar 18, 2024
@cgytrus cgytrus marked this pull request as draft April 4, 2024 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x refactor / cleanup Improves readability or maintainability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants