Skip to content

C-Sharp API related fixes - #1860

Merged
praydog merged 3 commits into
praydog:masterfrom
ZGako:csharp-api-pr-branch
Oct 10, 2026
Merged

praydog merged 3 commits into
praydog:masterfrom
ZGako:csharp-api-pr-branch

Conversation

@ZGako

@ZGako ZGako commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

I'll copy paste the commit messages as they're descriptive enough:

  • Fixed SynchronousUnload not calling PluginExitPoint
    Previously the only time PluginExitPoint was called was when all the plugins were being unloaded (pressing the "Unload Scripts" button).
    This meant that if a plugin was unloaded on its own (via SynchronousUnload), PluginExitPoint would not be called, which could lead to issues if the plugin was relying on that function to clean up resources.

  • Fixed function signature of exported cimgui functions
    cimgui was exporting suffixed igGetForegroundDrawList_Nil and igGetBackgroundDrawList_Nil functions,
    however when attempting to call said functions from C# plugins they wouldn't be found (leading to game crash) due to the correct signature being
    without the suffixes. To address this I added aliases igGetForegroundDrawList and igGetBackgroundDrawList that
    call the same underlying c++ functions.

  • Fix signed ref-count detection for local MOs
    The engine uses negative ref counts to identify thread-local managed objects, but the ABI exposes the value as unsigned. Cast it to int32_t before comparison so local objects bypass the shared wrapper cache and pool, preventing incorrect cross-thread reuse of thread-local objects.
    In particular this issue would crop up when creating strings inside an UpdateBehavior callback. I assume the C# multi-threading would cause this.

I'm aware cimgui isn't in the csharp-api folder however this fix is related to being able to utilize ImGui properly from the C# plugins.

ZGako added 3 commits October 8, 2026 19:11
Previously the only time PluginExitPoint was called was when all the plugins were being unloaded (pressing the "Unload Scripts" button).
This meant that if a plugin was unloaded on its own (via SynchronousUnload), PluginExitPoint would not be called, which could lead to issues if the plugin was relying on that function to clean up resources.
cimgui was exporting suffixed igGetForegroundDrawList_Nil and igGetBackgroundDrawList_Nil functions,
however when attempting to call said functions from C# plugins they wouldn't be found (leading to game crash) due to the correct signature being
without the suffixes. To address this I added aliases igGetForegroundDrawList and igGetBackgroundDrawList that
call the same underlying c++ functions.
The engine uses negative ref counts to identify thread-local managed objects,
but the ABI exposes the value as unsigned. Cast it to int32_t before
comparison so local objects bypass the shared wrapper cache and pool,
preventing incorrect cross-thread reuse of thread-local objects.
@praydog
praydog merged commit b47842c into praydog:master Oct 10, 2026
1 check passed
@ZGako
ZGako deleted the csharp-api-pr-branch branch October 10, 2026 23:00
onehoon added a commit to onehoon/REFramework that referenced this pull request Oct 11, 2026
* SDK/API: Fix get_ref_count being unsigned (< 0 are local-thread MO)

(cherry picked from commit 94a1218)

* C-Sharp API related fixes (praydog#1860)

* Fixed SynchronousUnload not calling PluginExitPoint

Previously the only time PluginExitPoint was called was when all the plugins were being unloaded (pressing the "Unload Scripts" button).
This meant that if a plugin was unloaded on its own (via SynchronousUnload), PluginExitPoint would not be called, which could lead to issues if the plugin was relying on that function to clean up resources.

* Fixed function signature of exported cimgui functions

cimgui was exporting suffixed igGetForegroundDrawList_Nil and igGetBackgroundDrawList_Nil functions,
however when attempting to call said functions from C# plugins they wouldn't be found (leading to game crash) due to the correct signature being
without the suffixes. To address this I added aliases igGetForegroundDrawList and igGetBackgroundDrawList that
call the same underlying c++ functions.

* Fix signed ref-count detection for local MOs

The engine uses negative ref counts to identify thread-local managed objects,
but the ABI exposes the value as unsigned. Cast it to int32_t before
comparison so local objects bypass the shared wrapper cache and pool,
preventing incorrect cross-thread reuse of thread-local objects.

(cherry picked from commit b47842c)

* fix: package path should contain autorun (praydog#1863)

Signed-off-by: LingSamuel <lingsamuelgrace@gmail.com>
(cherry picked from commit d7d59ad)

* Preserve the previous session log across restarts (praydog#1846)

re2_framework_log.txt was opened with truncate=true, so the previous
session's log was destroyed as soon as the framework was loaded. After a
crash this made it impossible to inspect the log of the session that
crashed: restarting the game, which is the first thing anyone does, had
already overwritten it.

Rename the existing log to re2_framework_log.prev.txt before creating the
logger, so the previous session survives a restart. All filesystem calls
use the std::error_code overloads, so a failure (e.g. a locked file)
quietly falls back to the old behaviour instead of blocking startup. At
most one previous session is kept: an existing .prev.txt is removed before
the rename.

(cherry picked from commit c36e8c4)

* .NET: Add console window display option

(cherry picked from commit d052e8f)

---------

Signed-off-by: LingSamuel <lingsamuelgrace@gmail.com>
Co-authored-by: praydog <praydog@praydog.com>
Co-authored-by: Gino <60258854+ZGako@users.noreply.github.com>
Co-authored-by: Sarasa Kisaragi <lingsamuelgrace@gmail.com>
Co-authored-by: wdre9 <15378433390@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants