-
-
Notifications
You must be signed in to change notification settings - Fork 552
Fix hugely popular crash in RpAnimBlendAllocateData (SA 0x000D5F6F) #4894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Dutchman101
wants to merge
2
commits into
multitheftauto:master
Choose a base branch
from
Dutchman101:animcrashfix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+141
−19
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2832,29 +2832,32 @@ static void __declspec(naked) HOOK_CVolumetricShadowMgr_Update() | |
| //////////////////////////////////////////////////////////////////////// | ||
| // CAnimManager::CreateAnimAssocGroups | ||
| // | ||
| // CModelInfo::ms_modelInfoPtrs at the given index is a null pointer | ||
| // Missing model info or RwObject before the clump is used for associations | ||
| //////////////////////////////////////////////////////////////////////// | ||
| void OnMY_CAnimManager_CreateAnimAssocGroups(uint uiModelId) | ||
| bool OnMY_CAnimManager_CreateAnimAssocGroups(uint uiModelId) | ||
| { | ||
| CModelInfo* pModelInfo = pGameInterface->GetModelInfo(uiModelId); | ||
| CBaseModelInfoSAInterface* pInterface = pModelInfo ? pModelInfo->GetInterface() : nullptr; | ||
| if (!pInterface || pInterface->pRwObject == nullptr) | ||
| if (!pInterface || !pInterface->pRwObject) | ||
| { | ||
| // Crash will occur at offset 00349b7b | ||
| OnCrashAverted(816); | ||
| LogEvent(816, "Model not loaded", "CAnimManager_CreateAnimAssocGroups", SString("No RwObject for model:%d", uiModelId), 5416); | ||
| CArgMap argMap; | ||
| argMap.Set("id", uiModelId); | ||
| argMap.Set("reason", "createanim"); | ||
| SetApplicationSetting("diagnostics", "gta-model-fail", argMap.ToString()); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| // Hook info | ||
| #define HOOKPOS_CAnimManager_CreateAnimAssocGroups 0x4D3D52 | ||
| #define HOOKSIZE_CAnimManager_CreateAnimAssocGroups 5 | ||
| #define HOOKCHECK_CAnimManager_CreateAnimAssocGroups 0x8B | ||
| DWORD RETURN_CAnimManager_CreateAnimAssocGroups = 0x4D3D59; | ||
| static void __declspec(naked) HOOK_CAnimManager_CreateAnimAssocGroups() | ||
| DWORD RETURN_CAnimManager_CreateAnimAssocGroups = 0x4D3D59; | ||
| DWORD RETURN_CAnimManager_CreateAnimAssocGroups_Skip = 0x4D3D71; | ||
| void _declspec(naked) HOOK_CAnimManager_CreateAnimAssocGroups() | ||
| { | ||
| MTA_VERIFY_HOOK_LOCAL_SIZE; | ||
|
|
||
|
|
@@ -2865,15 +2868,80 @@ static void __declspec(naked) HOOK_CAnimManager_CreateAnimAssocGroups() | |
| push eax | ||
| call OnMY_CAnimManager_CreateAnimAssocGroups | ||
| add esp, 4*1 | ||
| test al, al | ||
| popad | ||
| jz skipCreateInstance | ||
|
|
||
| // Replaced code | ||
| // Replaced code | ||
| push ecx | ||
| mov ecx, dword ptr[ARRAY_ModelInfo] | ||
| mov eax, dword ptr[ecx + eax*4] | ||
| pop ecx | ||
|
|
||
| jmp RETURN_CAnimManager_CreateAnimAssocGroups | ||
|
|
||
| skipCreateInstance: | ||
| xor ebx, ebx | ||
| jmp RETURN_CAnimManager_CreateAnimAssocGroups_Skip | ||
| } | ||
| // clang-format on | ||
| } | ||
|
|
||
| void OnMY_CAnimBlendAssocGroup_CreateAssociations(CBaseModelInfoSAInterface* pModelInfo) | ||
| { | ||
| OnCrashAverted(816); | ||
|
|
||
| int iModelId = -1; | ||
| CBaseModelInfoSAInterface** ppModelInfo = (CBaseModelInfoSAInterface**)ARRAY_ModelInfo; | ||
| const int maximumModelId = pGameInterface->GetBaseIDforTXD(); | ||
| for (int i = 0; i < maximumModelId; i++) | ||
| { | ||
| if (ppModelInfo[i] == pModelInfo) | ||
| { | ||
| iModelId = i; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| LogEvent(816, "Model not loaded", "CAnimBlendAssocGroup_CreateAssociations", SString("No RwObject for model:%d", iModelId), 5416); | ||
| CArgMap argMap; | ||
| argMap.Set("id", iModelId); | ||
| argMap.Set("reason", "createassoc"); | ||
| SetApplicationSetting("diagnostics", "gta-model-fail", argMap.ToString()); | ||
| } | ||
|
|
||
| #define HOOKPOS_CAnimBlendAssocGroup_CreateAssociations 0x4CE2F7 | ||
| #define HOOKSIZE_CAnimBlendAssocGroup_CreateAssociations 7 | ||
| #define HOOKCHECK_CAnimBlendAssocGroup_CreateAssociations 0x8B | ||
| DWORD RETURN_CAnimBlendAssocGroup_CreateAssociations = 0x4CE2FE; | ||
| DWORD RETURN_CAnimBlendAssocGroup_CreateAssociations_Skip = 0x4CE36F; | ||
| void _declspec(naked) HOOK_CAnimBlendAssocGroup_CreateAssociations() | ||
|
Comment on lines
+2913
to
+2918
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please could you write some comments explaining exactly what the hook does? |
||
| { | ||
| // clang-format off | ||
|
|
||
| MTA_VERIFY_HOOK_LOCAL_SIZE; | ||
| __asm | ||
| { | ||
| test eax, eax | ||
| jz skipCreateAssociation | ||
| cmp dword ptr[eax+1Ch], 0 | ||
| jnz continueCreateAssociation | ||
|
|
||
| pushad | ||
| push eax | ||
| call OnMY_CAnimBlendAssocGroup_CreateAssociations | ||
| add esp, 4*1 | ||
| popad | ||
| jmp skipCreateAssociation | ||
|
|
||
| continueCreateAssociation: | ||
| mov edx, [eax] | ||
| mov ecx, eax | ||
| call dword ptr[edx+2Ch] | ||
| jmp RETURN_CAnimBlendAssocGroup_CreateAssociations | ||
|
|
||
| skipCreateAssociation: | ||
| jmp RETURN_CAnimBlendAssocGroup_CreateAssociations_Skip | ||
| } | ||
| // clang-format on | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes here seem to be guarding against
m_pModelInfopointing to invalid data, but do we know why it's invalid in the first place?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Seems like a use after free or something?)