Jump to content

Modder PSA Re: RegisterForKey()


Recommended Posts

I posted this a while back in the SLS thread. Not really looking for support. It's more of a PSA for modders regarding RegisterForKey().

 

;tldr: Add checks to ensure you are never, ever Registering for key 0. 

 

Link to original post: https://www.loverslab.com/topic/99955-sexlab-survival/?do=findComment&comment=3148338

 

Quote


A bit of a PSA folks. It seems I've stumbled upon a serious-ish undocumented bug in papyrus. 

 

If a mod RegistersForKey(0)

zero specifically. This probably wouldn't be that unusual. Integers are initialized as 0. So if you do:

 

Int MyKeyCode

 

Event OnInit()

    RegisterForKey(MyKeyCode)

EndEvent

 

It would register 0.

 

Then if any mod comes along and does: Input.TapKey(Whateverkey)

It will create hundreds of OnKeyDown Events in the registered mod. Creating a lot of stacked script instances and eventually stack dumps. Not to talk about noticeable script lag. 

I guess Input.Tapkey() will cause problems with any key but it's definitely the case with using Mouse1. 

 

I discovered this while creating an 'auto fucker' script for SLSO - pressing mouse1 periodically. Every maybe 0.5 seconds tops. 

 

I've added checks that the keys in survival aren't being registered for 0. I'll double check STA. And I'm working on adding a check to BiS. I've also mentioned it to Ed for SLSO. 

 

I don't see this mentioned in the wiki. So just something to keep an eye on for with mods that have hotkeys.....

 

Pic:

Untitled.jpg.b6eccb74feec7dd305fa1e18f5b95919.jpg.5bb9ed79548c96367374a55f11c545b5.jpg

 

 

Link to comment
  • 4 months later...

had a peek into the SKSE64 source (don't have the oldrim SKSE source handy atm):

Spoiler

191 |   for (InputEvent * e = *evns; e; e = e->next)
  1 |   {
  2 |   |   switch(e->eventType)
  3 |   |   {
  4 |   |   |   case InputEvent::kEventType_Button:
  5 |   |   |   |   {
  6 |   |   |   |   |   ButtonEvent * t = DYNAMIC_CAST(e, InputEvent, ButtonEvent);
  7
  8
  9 |   |   |   |   |   UInt32| keyCode;
 10 |   |   |   |   |   UInt32| deviceType = t->deviceType;
 11 |   |   |   |   |   UInt32| keyMask = t->keyMask;
 12
 13 |   |   |   |   |   // Mouse
 14 |   |   |   |   |   if (deviceType == kDeviceType_Mouse)
 15 |   |   |   |   |   |   keyCode = InputMap::kMacro_MouseButtonOffset + keyMask;
 16 |   |   |   |   |   // Gamepad
 17 |   |   |   |   |   else if (deviceType == kDeviceType_Gamepad)
 18 |   |   |   |   |   |   keyCode = InputMap::GamepadMaskToKeycode(keyMask);
 19 |   |   |   |   |   // Keyboard
 20 |   |   |   |   |   else
 21 |   |   |   |   |   |   keyCode = keyMask;
 22
 23 |   |   |   |   |   // Valid scancode?
 24 |   |   |   |   |   if (keyCode >= InputMap::kMaxMacros)
 25 |   |   |   |   |   |   continue;
 26
 27 |   |   |   |   |   BSFixedString|  control|= *t->GetControlID();
 28 |   |   |   |   |   float|  |   |   timer|  = t->timer;
 29
 30 |   |   |   |   |   bool isDown|= t->flags != 0 && timer == 0.0;
 31 |   |   |   |   |   bool isUp|  = t->flags == 0 && timer != 0;
 32
 33 |   |   |   |   |   if (isDown)
 34 |   |   |   |   |   {
 35 |   |   |   |   |   |   // Used by scaleform skse.GetLastControl
 36 |   |   |   |   |   |   SetLastControlDown(control.data, keyCode);
 37
 38 |   |   |   |   |   |   g_inputKeyEventRegs.ForEach(
 39 |   |   |   |   |   |   |   keyCode,
 40 |   |   |   |   |   |   |   EventQueueFunctor1<SInt32>(BSFixedString("OnKeyDown"), (SInt32)keyCode)
 41 |   |   |   |   |   |   |   );
 42 |   |   |   |   |   |   g_inputControlEventRegs.ForEach(
 43 |   |   |   |   |   |   |   control,
 44 |   |   |   |   |   |   |   EventQueueFunctor1<BSFixedString>(BSFixedString("OnControlDown"), control)
 45 |   |   |   |   |   |   |   );
 46 |   |   |   |   |   }
 47 |   |   |   |   |   else if (isUp)
 48 |   |   |   |   |   {
 49 |   |   |   |   |   |   SetLastControlUp(control.data, keyCode);
 50
 51 |   |   |   |   |   |   g_inputKeyEventRegs.ForEach(
 52 |   |   |   |   |   |   |   keyCode,
 53 |   |   |   |   |   |   |   EventQueueFunctor2<SInt32, float>(BSFixedString("OnKeyUp"), (SInt32)keyCode, timer)
 54 |   |   |   |   |   |   |   );
 55 |   |   |   |   |   |   g_inputControlEventRegs.ForEach(
 56 |   |   |   |   |   |   |   control,
 57 |   |   |   |   |   |   |   EventQueueFunctor2<BSFixedString, float>(BSFixedString("OnControlUp"), control, timer)
 58 |   |   |   |   |   |   |   );
 59 |   |   |   |   |   }
 60 |   |   |   |   }
 61 |   |   |   |   break;
 62
 63 |   |   |   /*case InputEvent::kEventType_Thumbstick:
 64 |   |   |   |   {
 65 |   |   |   |   |   ThumbstickEvent * t = DYNAMIC_CAST(e, InputEvent, ThumbstickEvent);
 66 |   |   |   |   |   _MESSAGE("Moved %s Stick X: %f Y: %f", t->keyMask == 0x0B ? "Left" : "Right", t->x, t->y);
 67 |   |   |   |   }
 68 |   |   |   |   break;*/
 69 |   |   }
 70 |   }

 

lines 23-25 could probably easily be modified to:

 23 |   |   |   |   |   // Valid scancode?
 24 |   |   |   |   |   if (keyCode >= InputMap::kMaxMacros || keycode == 0)
 25 |   |   |   |   |   |   continue;

 

0 should not be a valid DX scancode anyways.

 

might be worth contacting the SKSE team about:
team [at] skse [dot] silverlock [dot] org

but thus far i don't think i've had that bug

Link to comment
  • 1 month later...
On 4/22/2021 at 12:24 AM, yeahhowaboutnooo said:

might be worth contacting the SKSE team about

I'd imagine the likelihood of anything being done about it at this point being pretty slim anyway. 

On 4/22/2021 at 12:24 AM, yeahhowaboutnooo said:

but thus far i don't think i've had that bug

Most occurrences are probably handled easily enough - even though a lot of instances might be spawned from a single click most mods are probably not using Input.TapKey more than once every now and then. Unlike compulsive sex. It's also possible it's something to do with specifically InputTapKey(Mouse1).

Link to comment
  • 7 months later...
On 12/16/2020 at 6:03 PM, Monoman1 said:

I posted this a while back in the SLS thread. Not really looking for support. It's more of a PSA for modders regarding RegisterForKey().

 

;tldr: Add checks to ensure you are never, ever Registering for key 0. 

 

Link to original post: https://www.loverslab.com/topic/99955-sexlab-survival/?do=findComment&comment=3148338

 

 

 

Hey Monoman, do you know if anyone made a patch for this for Bathing in Skyrim yet? I had a look around but couldn't find one. Whenever I used BiS it bloated my game to death.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use