Dingf / GDCommunityLauncher

The launcher for the Grim Dawn Community League project
MIT License
1 stars 2 forks source link

Fix duplicate item links #6

Closed 12foo closed 1 year ago

12foo commented 1 year ago

Seems to be a case of pointer reuse internally. Forcing a fresh one seems to fix it. Should fix #5

Dingf commented 1 year ago

In theory, this seems like the item pointer being passed into GameAPI::AddChatMessage() should be identical. I can pull the changes and ask Eluminator to test, since he encounters the issue somewhat frequently.

Were you able to reproduce the issue consistently prior to this change?

12foo commented 1 year ago

Yep, I was really lucky/unlucky with this particular bug, and after this change it was gone.

Dingf commented 1 year ago

I pulled the changes and asked Eluminator to test, but he is still seeing the same issues afterwards.

image

12foo commented 1 year ago

Hmm, that's odd. I can, in any case, confirm that the data is correct all the way until GameAPI::CreateItem(itemInfo), and since that result is a void* I can't look further into it. But it's definitely happening inside the CreateItem call, or when it's handed over to AddChatMessage. I speculate that it's some sort of undefined behavior, or the compiler is optimizing it wrong.

Dingf commented 1 year ago

Yeah, that matches what I've been seeing as well. It seems like there's some strange behavior happening internally either within the GameAPI::AddChatMesssage function or the GameAPI::CreateItem function that only affects some users. My best guess would be that since we are creating the item immediately before calling the function, the item isn't fully registered in the object manager which causes the lookup to fail and the function links the last known item instead.

I'll see if I can put in some debug statements that dump the address of the item pointer when an item is linked. In theory, if the pointers are different, then that should indicate that the problem lies within GameAPI::AddChatMesssage. In either case however, I suspect that this bug may be very difficult/nearly impossible to fix since the issue seems to be within the in-game functions and not with the launcher code.

Dingf commented 1 year ago

Actually nvm, it seems like there are some duplicates. Strange.

GDCommunityLauncher.log

12foo commented 1 year ago

I'm thinking maybe it's some sort of caching mechanism, and there's some field in the item replica that's not being set correctly to actually invalidate the cache.

Dingf commented 1 year ago

As far as I can tell, the ItemReplicaInfo struct should be complete unless it's one of the unk fields or some additional data afterwards. Could be worth playing around with, though it's still odd that it only breaks for certain people.

Dingf commented 1 year ago

The most recent hotfix that I pushed up fixed item linking for some people. This change was just adding some extra unknown fields to the ItemReplicaInfo struct, so the culprit was likely the in-game function reading past the bounds of the ItemReplicaInfo struct and getting invalid/corrupt data.

Eluminator reported that he was still seeing item linking issues after the hotfix, so there might be more to it than that. But for now, I'm closing the ticket since the fix seems to be unrelated.