Skip to content

Commit 9889ce7

Browse files
Bugfix: Swapping characters could result in repeated nesting of the inventory function hook
1 parent 984edcb commit 9889ce7

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

GlitterGone/GlitterGone.incl.as

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function onLoad():Void {
1414
if (_global.efd.GlitterGone == undefined) { _global.efd.GlitterGone = new Object(); }
1515

1616
HookUI(false); // Tries a pre-emptive hook, in case the protoype has been pre-loaded
17-
if (!_global.efd.GlitterGone.HookApplied) { // Could not apply hook, setup triggers to try later
17+
if (!_global.efd.GlitterGone.AgentIconHookApplied) { // Could not apply hook, setup triggers to try later
1818
AgentWindow = DistributedValue.Create("agentSystem_window");
1919
AgentWindow.SignalChanged.Connect(HookAgentWindow, this);
2020
HookItemUse();
@@ -25,7 +25,7 @@ function onLoad():Void {
2525
// Permits multiple mods hooking a single function without having to ensure a unique name for each nested copy
2626
// Side-effect based conflicts may still occur, hooking order is arbitrary and there is no way to safely disconnect a hook after the fact
2727
function HookUI(useTimeout:Boolean):Void {
28-
if (!_global.efd.GlitterGone.HookApplied) {
28+
if (!_global.efd.GlitterGone.AgentIconHookApplied) {
2929
var proto:Object = _global.GUI.AgentSystem.RosterIcon.prototype;
3030
if (proto) {
3131
var wrapper:Function = function():Void {
@@ -35,7 +35,7 @@ function HookUI(useTimeout:Boolean):Void {
3535
};
3636
wrapper.Base = proto.UpdateVisuals;
3737
proto.UpdateVisuals = wrapper;
38-
_global.efd.GlitterGone.HookApplied = true;
38+
_global.efd.GlitterGone.AgentIconHookApplied = true;
3939

4040
// AgentUnlock window loads before hook is applied and doesn't update visuals
4141
// So force a refresh if the window exists
@@ -48,16 +48,19 @@ function HookUI(useTimeout:Boolean):Void {
4848

4949
function HookAgentWindow(dv:DistributedValue):Void { HookUI(dv.GetValue()); }
5050
function HookItemUse():Void { // Triggers a hook attempt when an agent dossier is used from within main inventory
51-
var wrapper:Function = function(itemPos:Number):Void {
52-
arguments.callee.Base.apply(this, arguments);
53-
if (this.GetItemAt(itemPos).m_ItemTypeGUI == 253188674 &&
54-
this.GetInventoryID().m_Type == _global.Enums.InvType.e_Type_GC_BackpackContainer) {
55-
HookUI(true);
51+
if (!_global.efd.GlitterGone.InventoryHookApplied) {
52+
var wrapper:Function = function(itemPos:Number):Void {
53+
arguments.callee.Base.apply(this, arguments);
54+
if (this.GetItemAt(itemPos).m_ItemTypeGUI == 253188674 &&
55+
this.GetInventoryID().m_Type == _global.Enums.InvType.e_Type_GC_BackpackContainer) {
56+
HookUI(true);
57+
}
5658
}
59+
var proto:Object = _global.com.GameInterface.Inventory.prototype; // This one pre-loads
60+
wrapper.Base = proto.UseItem;
61+
proto.UseItem = wrapper;
62+
_global.efd.GlitterGone.InventoryHookApplied = true;
5763
}
58-
var proto:Object = _global.com.GameInterface.Inventory.prototype; // This one pre-loads
59-
wrapper.Base = proto.UseItem;
60-
proto.UseItem = wrapper;
6164
}
6265

6366
var AgentWindow:DistributedValue;

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ The packaged release should be unzipped (including the internal folder) into the
2020
Defect reports are always welcome. The forum post is the ideal place to leave a message, but I also track the CurseForge comments and GitHub's issue tracker. For little things or quick troubleshooting flag me down in discord (@Peloprata on the official server's #modding channel) or look for me in game (often lurking in #Sanctuary).
2121

2222
## Change Log
23-
**Version 1.1**
23+
Version 1.1.1
24+
+ Bugfix: Swapping characters several thousand times no longer runs risk of slow inventory item usage
25+
26+
Version 1.1
2427
+ Swept the glitter out of the corner cases (already open agent interface, agent dossiers)
2528
+ Uses a new and improved function hook, which should eliminate the risk of one particular type of compatibility bug
2629

27-
**Version 1.0**
30+
Version 1.0
2831
+ Released
2932

3033
## License and Attribution

0 commit comments

Comments
 (0)