Skip to content

Commit a67104e

Browse files
committed
Added AddScrap callback
1 parent f719b71 commit a67104e

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

ExtraUtilities.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
</Link>
139139
</ItemDefinitionGroup>
140140
<ItemGroup>
141+
<ClCompile Include="src\AddScrapCallback.cpp" />
141142
<ClCompile Include="src\BulletHitCallback.cpp" />
142143
<ClCompile Include="src\BulletInitCallback.cpp" />
143144
<ClCompile Include="src\Camera.cpp" />
@@ -164,6 +165,7 @@
164165
</ItemGroup>
165166
<ItemGroup>
166167
<ClInclude Include="src\About.h" />
168+
<ClInclude Include="src\AddScrapCallback.h" />
167169
<ClInclude Include="src\BulletHitCallback.h" />
168170
<ClInclude Include="src\BulletInitCallback.h" />
169171
<ClInclude Include="src\BZR.h" />

ExtraUtilities.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
<ClCompile Include="src\OrdnanceVelocity.cpp">
100100
<Filter>Source Files\Patches</Filter>
101101
</ClCompile>
102+
<ClCompile Include="src\AddScrapCallback.cpp">
103+
<Filter>Source Files\Patches</Filter>
104+
</ClCompile>
102105
</ItemGroup>
103106
<ItemGroup>
104107
<ClInclude Include="src\About.h">
@@ -194,5 +197,8 @@
194197
<ClInclude Include="src\Ogre.h">
195198
<Filter>Header Files</Filter>
196199
</ClInclude>
200+
<ClInclude Include="src\AddScrapCallback.h">
201+
<Filter>Header Files\Patches</Filter>
202+
</ClInclude>
197203
</ItemGroup>
198204
</Project>

src/AddScrapCallback.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* Copyright (C) 2023-2025 VTrider
2+
*
3+
* This file is part of Extra Utilities.
4+
*
5+
* Extra Utilities is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU Lesser General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or (at your
8+
* option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12+
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13+
* details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "AddScrapCallback.h"
20+
21+
#include "Hook.h"
22+
#include "LuaState.h"
23+
24+
namespace ExtraUtilities::Patch
25+
{
26+
static void __cdecl LuaCallback(uint32_t teamNumber, uint32_t scrapAmount)
27+
{
28+
lua_State* L = Lua::state;
29+
30+
lua_getglobal(L, "exu");
31+
lua_getfield(L, -1, "AddScrap");
32+
33+
if (!lua_isfunction(L, -1))
34+
{
35+
return;
36+
}
37+
38+
lua_pushinteger(L, teamNumber);
39+
lua_pushinteger(L, scrapAmount);
40+
41+
lua_call(L, 2, 0);
42+
43+
lua_pop(L, -1);
44+
}
45+
46+
static void __declspec(naked) AddScrapCallback()
47+
{
48+
__asm
49+
{
50+
/*
51+
* Notes:
52+
*
53+
* Team object in ecx
54+
* team number in ecx+0x180
55+
*
56+
* Scrap amount to add in param 1/ebp+0x08
57+
*/
58+
59+
// Game code - side note why tf is it doing this lol
60+
mov [ebp-0x04], ecx
61+
mov ecx, [ebp-0x04]
62+
63+
pushad
64+
pushfd
65+
66+
mov eax, [ebp+0x08] // scrap amount
67+
push eax
68+
mov ecx, [ecx+0x180] // team number
69+
push ecx
70+
call LuaCallback
71+
add esp, 0x08
72+
73+
popfd
74+
popad
75+
76+
ret
77+
}
78+
}
79+
Hook addScrapHook(addScrap, &AddScrapCallback, 6, BasicPatch::Status::ACTIVE);
80+
}

src/AddScrapCallback.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Copyright (C) 2023-2025 VTrider
2+
*
3+
* This file is part of Extra Utilities.
4+
*
5+
* Extra Utilities is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU Lesser General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or (at your
8+
* option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12+
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13+
* details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#pragma once
20+
21+
#include <cstdint>
22+
23+
namespace ExtraUtilities::Patch
24+
{
25+
constexpr uintptr_t addScrap = 0x005E1016;
26+
}

0 commit comments

Comments
 (0)