Skip to content

Commit c439b88

Browse files
committed
fix(integration): ensure CPR usability for players during import
Either CPR's "Item Configuration Access" option or "Item Replacer Access" option needs to be enabled, to allow the integration to grab the appropriate hook. Without this, the integration does not work for non-GM users. As "Item Configuration Access" is the lesser of these two options (it allows players to e.g. adjust the animations, damage types, etc. of their CPR items), only require that it be enabled, rather than full "Item Replacer Access" (which has a greater potential for misuse). Then, during our CPR-data-fetching step, add a player-only patch to "enable" the "Item Replacer Access" option, such that we can update our temp items. In practical terms, this is either done for too short an interval for the player to notice, or is done while wider activity has probably locked up the main thread and is preventing any user interaction anyway, so shouldn't present much opportunity for damage (intentional or otherwise [the same "intentional" trick could be pulled much easier with a console one-liner!]).
1 parent e9f1cd5 commit c439b88

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

module/js/SettingsManager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export class SettingsManager extends StartupHookMixin(class {}) {
6464
expectedValue: "showOriginal",
6565
},
6666
// region chris-premades
67+
{moduleId: this._MODULE_ID__CHRIS_PREMADES, isGmOnly: true, settingKey: "Item Configuration Access", displaySettingName: "Item Configuration Access", expectedValue: true},
68+
6769
{moduleId: this._MODULE_ID__CHRIS_PREMADES, isGmOnly: true, settingKey: "Effect Auras", displaySettingName: "Effect Auras", expectedValue: true},
6870
{moduleId: this._MODULE_ID__CHRIS_PREMADES, isGmOnly: true, settingKey: "On Hit", displaySettingName: "On Hit", expectedValue: true},
6971
{moduleId: this._MODULE_ID__CHRIS_PREMADES, isGmOnly: true, settingKey: "Combat Listener", displaySettingName: "Combat Listener", expectedValue: true},

module/js/integrations/ChrisPremades.js

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,18 @@ export class IntegrationChrisPremades extends StartupHookMixin(IntegrationBase)
6666

6767
_stubSemaphores = {};
6868

69-
async _pWithStubbed (nameStubbed, fn, {returnValue} = {}) {
69+
async _pWithStubbed (nameStubbed, {returnValue, fnPatch} = {}, fn) {
7070
let out;
7171
// Only register/deregister on semaphore 0 to avoid libWrapper errors (a module may only patch a method once)
7272
try {
7373
this._stubSemaphores[nameStubbed] = this._stubSemaphores[nameStubbed] || 0;
7474
if (!this._stubSemaphores[nameStubbed]++) {
75-
libWrapper.register(SharedConsts.MODULE_ID, nameStubbed, () => returnValue, _LIBWRAPPER_TYPE_TEMP);
75+
libWrapper.register(
76+
SharedConsts.MODULE_ID,
77+
nameStubbed,
78+
(fnOriginal, ...args) => fnPatch ? fnPatch(fnOriginal, ...args) : returnValue,
79+
_LIBWRAPPER_TYPE_TEMP,
80+
);
7681
}
7782
out = await fn();
7883
} finally {
@@ -135,30 +140,42 @@ export class IntegrationChrisPremades extends StartupHookMixin(IntegrationBase)
135140
) {
136141
return this._pWithStubbed(
137142
"ui.notifications.info",
143+
{},
138144
() => this._pWithStubbed(
139-
"chrisPremades.helpers.dialog",
140-
() => this._pWithStubbed(
141-
"ChatMessage.create",
142-
this._pGetExpandedAddonData_pWithStubbed
143-
.bind(
144-
this,
145-
{
146-
propJson,
147-
path,
148-
fnMatch,
149-
ent,
150-
propBase,
151-
base,
152-
actorType,
153-
isSilent,
154-
},
155-
),
156-
),
145+
"game.settings.get",
157146
{
158-
returnValue: CONFIG.chrisPremades.itemConfiguration[ent.name]
159-
? "update"
160-
: true,
147+
fnPatch: (fn, ...args) => {
148+
const [module, key] = args;
149+
if (!game.user.isGM && module === "chris-premades" && key === "Item Replacer Access") return true;
150+
return fn(...args);
151+
},
161152
},
153+
() => this._pWithStubbed(
154+
"chrisPremades.helpers.dialog",
155+
{
156+
returnValue: CONFIG.chrisPremades.itemConfiguration[ent.name]
157+
? "update"
158+
: true,
159+
},
160+
() => this._pWithStubbed(
161+
"ChatMessage.create",
162+
{},
163+
this._pGetExpandedAddonData_pWithStubbed
164+
.bind(
165+
this,
166+
{
167+
propJson,
168+
path,
169+
fnMatch,
170+
ent,
171+
propBase,
172+
base,
173+
actorType,
174+
isSilent,
175+
},
176+
),
177+
),
178+
),
162179
),
163180
);
164181
}

0 commit comments

Comments
 (0)