Skip to content

Commit fd3d8cb

Browse files
committed
feat(common): repentance+ check functions
1 parent 343b321 commit fd3d8cb

File tree

2 files changed

+27
-1
lines changed
  • packages
    • isaac-typescript-definitions/src/types
    • isaacscript-common/src/functions

2 files changed

+27
-1
lines changed

packages/isaac-typescript-definitions/src/types/main.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ declare function StartDebug(): void;
3232
* @deprecated
3333
*/
3434
declare const REPENTANCE: never;
35+
36+
/**
37+
* This can be overwritten by other mods, so it is not safe to use. Use the `isRepentancePlus`
38+
* helper function instead.
39+
*
40+
* @deprecated
41+
*/
42+
declare const REPENTANCE_PLUS: never;

packages/isaacscript-common/src/functions/utils.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { game } from "../core/cachedClasses";
12
import { ReadonlySet } from "../types/ReadonlySet";
23
import { getAllPlayers } from "./playerIndex";
34
import { isFunction } from "./types";
@@ -155,7 +156,7 @@ export function isMultiplayer(): boolean {
155156
}
156157

157158
/**
158-
* Helper function to check if the player is using Afterbirth+ or Repentance.
159+
* Helper function to check if the player has the Repentance DLC installed.
159160
*
160161
* This function should always be used over the `REPENTANCE` constant, since the latter is not safe.
161162
*
@@ -181,6 +182,23 @@ export function isRepentance(): boolean {
181182
return isFunction(getAnimation);
182183
}
183184

185+
/**
186+
* Helper function to check if the player has the Repentance+ DLC installed.
187+
*
188+
* This function should always be used over the `REPENTANCE_PLUS` constant, since the latter is not
189+
* safe.
190+
*
191+
* Specifically, this function checks for `Room:DamageGridWithSource` method:
192+
* https://bindingofisaacrebirth.wiki.gg/wiki/The_Binding_of_Isaac:_Repentance%2B#Modding_Changes
193+
*/
194+
export function isRepentancePlus(): boolean {
195+
const room = game.GetRoom();
196+
const metatable = getmetatable(room) as LuaMap<string, unknown> | undefined;
197+
assertDefined(metatable, "Failed to get the metatable of the room class.");
198+
const damageGridWithSource = metatable.get("DamageGridWithSource");
199+
return isFunction(damageGridWithSource);
200+
}
201+
184202
/**
185203
* Helper function to check if the player is using REPENTOGON, an exe-hack which expands the modding
186204
* API.

0 commit comments

Comments
 (0)