Skip to content

Commit

Permalink
Compat for "A RimWorld of Magic" (#383)
Browse files Browse the repository at this point in the history
* Partial compat for "A RimWorld of Magic"

Originally started in 1.3, but abandoned due to 1.4 and Biotech releasing. Seems like all the patches currently done will work as-is.

However, the compat IS NOT FINISHED! Again, due to 1.4/Biotech releasing I dropped this compat, and then forgot about it.

* Update to RimWorld of Magic compat

While this compat is not yet complete, I believe at the moment the mod should be playable with most features working without an issue.

- The compat was changed from a normal to a referenced one
  - The complexity was starting to build up, so this allowed for a significantly simpler and slightly smaller code
  - This required including not only `TorannMagic` assembly (ARoM), but also `AbilityUser` (JecsTools) since it's a dependency and significantly limited what could be done without including it
- Simplified the patch to TM_MoteMaker RNG
  - Rather than directly targeting specific methods, the patch will target (almost) all methods with a void return
- Synced leveling up/learning skills and powers
  - The code here required quite a bit of work and patching a significant amount of the mod's methods
- Synced several gizmos and float menus (possibly all?)
- Synced opening portal interaction
  - The syncing removes the job the pawn takes, as at the end of the job they start an interaction - instead we do interaction first and skip the job
- Added several checks to sync methods that will stop execution if the method could not execute anymore at this point

A slight side note - at the moment this is the 3rd biggest compat (in file size/line count), right after Vehicle Framework and Vanilla Expanded Framework.

* Updated ARoM compat

Currently, the only thing left is to fix the multithreading for the living wall ability. Will need to either re-write the ticking method, or make a transpiler to handle it in a safe manner.

Changes:
- Simplified auto casting syncing
  - Doesn't use indexes but ability defs for syncing
- Fixed power learning replacing an extra button that wasn't supposed to be
- Fixed methods related to sprite areas passing null as map
  - They now use caster pawn's map (when casting) or sprite's actual map (in magic comp's)
- Synced changes to values in golem's ITab
- Synced golem rename dialog
- Synced golem dialog to change enabled abilities and work types

* Fix multithreading, optimize living wall

Multithreading fix should be done, some minor golem stuff that I forgot to test until now still needs fixing.

Changes:
- All previously multithreaded calls will be called on main thread
- The call to `DirectPath` will be only called when `idleFor` field is 0, which will prevent constantly calling this method
- The call to `DoThreadedActions` will be called normally, as it periodically calls its methods already
  - However, when a new value for `nextWallUpdate` field is set, it'll be multiplied by 6 to delay that specific call, as it's quite costly
- Optimized several methods related to Living Wall ability, making it feasible to use on main thread without issues
- Removed temporary debug logging for golems included in previous update

* Most likely finished the Rimworld of Magic compat

Tested several features in the mod, and the ones I got to test seemed to work fine. There may be something that's unsafe, but testing everything alone would be very time-consuming, so I'll go back and fix issues as they are found.

Changes:
- Synced golem main tab window
  - Several fields are watched that are also watched in ITab
  - (De)activation checkbox is a bit more complex
    - The syncing is cancelled if the golem is already in the process of being (de)activated
      - This was not required, but I've included it since I already was working on a prefix for this method
    - The execution of the synced method is cancelled if the golem is already in the requested state, as the mod has no checks for this
      - This required adding a transpiler to include the requested state in the sync method, since the mod uses `true` by default
  - This required syncing a method inside of one of PawnColumnWorkers, but since the main table is not a subtype of `MainTabWindow_PawnTable` but inherits directly from `MainTabWindow`, the MP's sync worker delegate for `PawnTable` doesn't work. Since it's useless I've transformed the argument and made a dummy one.
- Reworked how syncing `GolemAbilitiesWindow` works
  - Turns out, the checkboxes don't work on temporary values but the actual values - which needed watching sync fields
  - Syncing the `Close` method was also required due to it doing some things as well
  - This change requires update to `MpCompatPatchLoader` and MpCompat attributes to support sync fields with instance paths
- Added syncing of several static fields on join, as those are never reset when starting a new game, nor are they ever saved
  - This may cause bugs in the mod itself in a couple of situations
  - The `growthCells` list is cleared instead, since the mod attempts to (badly, as it may fail) to clear the list and re-add all values in
    - This ensures that the list is cleared when the mod attempts to add stuff to it
  - Replaced clearing of living wall's current target with syncing of the target, since we may as well do that to make joining feel a bit more seamless
- Added resetting of TM_GolemUpgradeDef workstation effects to their default value
  - Those values are modified by the mod while playing but never cleared and will cause desyncs when joining otherwise
    - The way the mod handles those may cause bugs with multiple golems of the same type
    - This will likely also cause issues with async time, as well as non-async time when the time gets out of sync
- Removed some `__state = false` calls, replaced `out` for `ref` for this argument
  - This matches MP itself a bit more closely and lowers the amount of code we need
  • Loading branch information
SokyranTheDragon authored Sep 27, 2024
1 parent 6887409 commit 215c945
Show file tree
Hide file tree
Showing 5 changed files with 1,795 additions and 0 deletions.
Binary file added References/AbilityUser.dll
Binary file not shown.
1 change: 1 addition & 0 deletions References/AbilityUser.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
018EB6AABB5223A1F76F03A0DD8E9F31E9FC7621
Binary file added References/TorannMagic.dll
Binary file not shown.
1 change: 1 addition & 0 deletions References/TorannMagic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
25A6D01C84C64F02846D29BC4454F9B294B5E228
Loading

0 comments on commit 215c945

Please sign in to comment.