Skip to content

Commit 94d2796

Browse files
committed
fix(core): Fix s2binlib call
1 parent a0873dd commit 94d2796

File tree

6 files changed

+97
-5
lines changed

6 files changed

+97
-5
lines changed

src/core/bridge/metamod.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ bool SwiftlyMMBridge::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxle
6868

6969
META_CONVAR_REGISTER(FCVAR_RELEASE | FCVAR_SERVER_CAN_EXECUTE | FCVAR_CLIENT_CAN_EXECUTE | FCVAR_GAMEDLL);
7070

71+
s2binlib_initialize(Plat_GetGameDirectory(), "csgo");
72+
s2binlib_set_module_base_from_pointer("server", g_ifaceService.FetchInterface<IServerGameDLL>(INTERFACEVERSION_SERVERGAMEDLL));
73+
s2binlib_set_module_base_from_pointer("engine2", g_ifaceService.FetchInterface<IVEngineServer2>(INTERFACEVERSION_VENGINESERVER));
74+
7175
void* serverSideClientVTable;
72-
s2binlib_find_vtable("server", "CServerSideClient", &serverSideClientVTable);
76+
s2binlib_find_vtable("engine2", "CServerSideClient", &serverSideClientVTable);
7377
OnConVarQueryID = SH_ADD_DVPHOOK(CServerSideClientBase, ProcessRespondCvarValue, (CServerSideClientBase*)serverSideClientVTable, SH_MEMBER(this, &SwiftlyMMBridge::OnConvarQuery), false);
7478

7579
auto server = g_ifaceService.FetchInterface<IServerGameDLL>(INTERFACEVERSION_SERVERGAMEDLL);

src/core/entrypoint.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ bool SwiftlyCore::Load(BridgeKind_t kind)
4747
m_iKind = kind;
4848
SetupConsoleColors();
4949

50-
s2binlib_initialize(Plat_GetGameDirectory(), "csgo");
51-
s2binlib_set_module_base_from_pointer("server", g_ifaceService.FetchInterface<IServerGameDLL>(INTERFACEVERSION_SERVERGAMEDLL));
52-
s2binlib_set_module_base_from_pointer("engine2", g_ifaceService.FetchInterface<IVEngineServer2>(INTERFACEVERSION_VENGINESERVER));
50+
51+
// s2binlib_pattern
5352

5453
auto logger = g_ifaceService.FetchInterface<ILogger>(LOGGER_INTERFACE_VERSION);
5554

src/memory/gamedata/manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ std::map<std::string, int> m_binariesSize;
7373

7474
void* FindSignature(std::string library, std::string pattern)
7575
{
76-
void* result;
76+
void* result = 0;
7777
s2binlib_pattern_scan(library.c_str(), pattern.c_str(), &result);
7878
return result;
7979

vendor/s2binlib/libs2binlib.a

198 KB
Binary file not shown.

vendor/s2binlib/s2binlib.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,95 @@ int s2binlib_pattern_scan(const char* binary_name, const char* pattern, void** r
8282
*/
8383
int s2binlib_pattern_scan_va(const char* binary_name, const char* pattern, void** result);
8484

85+
/**
86+
* Callback function type for pattern_scan_all functions
87+
*
88+
* @param index The index of the current match (0-based)
89+
* @param address The found address (VA or memory address depending on the function)
90+
* @param user_data User-provided data pointer
91+
* @return true to stop searching (found what you need), false to continue searching
92+
*/
93+
typedef bool (*s2binlib_pattern_scan_callback)(size_t index, void* address, void* user_data);
94+
95+
/**
96+
* Find all occurrences of a pattern in a binary and return their virtual addresses
97+
*
98+
* Scans the binary for all occurrences of the specified byte pattern and calls
99+
* the callback function for each match found. The callback receives virtual addresses (VA).
100+
*
101+
* If the binary is not yet loaded, it will be loaded automatically.
102+
*
103+
* @param binary_name Name of the binary to scan
104+
* @param pattern Byte pattern with wildcards (e.g., "48 89 5C 24 ? 48 89 74")
105+
* @param callback Function pointer that will be called for each match
106+
* @param user_data User-provided pointer passed to each callback invocation
107+
*
108+
* @return 0 on success (at least one match found)
109+
* -1 if S2BinLib not initialized
110+
* -2 if invalid parameters
111+
* -3 if failed to load binary
112+
* -4 if pattern not found
113+
* -5 if internal error
114+
*
115+
* @note The callback should return true to stop searching, false to continue
116+
*
117+
* @example
118+
* bool my_callback(size_t index, void* address, void* user_data) {
119+
* printf("Match #%zu found at VA: %p\n", index, address);
120+
* int* count = (int*)user_data;
121+
* (*count)++;
122+
* return false; // Continue searching
123+
* }
124+
*
125+
* int count = 0;
126+
* int result = s2binlib_pattern_scan_all_va("server", "48 89 5C 24 ?", my_callback, &count);
127+
* if (result == 0) {
128+
* printf("Found %d matches\n", count);
129+
* }
130+
*/
131+
int s2binlib_pattern_scan_all_va(const char* binary_name, const char* pattern,
132+
s2binlib_pattern_scan_callback callback, void* user_data);
133+
134+
/**
135+
* Find all occurrences of a pattern in a binary and return their memory addresses
136+
*
137+
* Scans the binary for all occurrences of the specified byte pattern and calls
138+
* the callback function for each match found. The callback receives memory addresses
139+
* (adjusted with module base address).
140+
*
141+
* If the binary is not yet loaded, it will be loaded automatically.
142+
*
143+
* @param binary_name Name of the binary to scan
144+
* @param pattern Byte pattern with wildcards (e.g., "48 89 5C 24 ? 48 89 74")
145+
* @param callback Function pointer that will be called for each match
146+
* @param user_data User-provided pointer passed to each callback invocation
147+
*
148+
* @return 0 on success (at least one match found)
149+
* -1 if S2BinLib not initialized
150+
* -2 if invalid parameters
151+
* -3 if failed to load binary
152+
* -4 if pattern not found
153+
* -5 if internal error
154+
*
155+
* @note The callback should return true to stop searching, false to continue
156+
*
157+
* @example
158+
* bool my_callback(size_t index, void* address, void* user_data) {
159+
* printf("Match #%zu found at memory address: %p\n", index, address);
160+
* int* count = (int*)user_data;
161+
* (*count)++;
162+
* return false; // Continue searching
163+
* }
164+
*
165+
* int count = 0;
166+
* int result = s2binlib_pattern_scan_all("server", "48 89 5C 24 ?", my_callback, &count);
167+
* if (result == 0) {
168+
* printf("Found %d matches\n", count);
169+
* }
170+
*/
171+
int s2binlib_pattern_scan_all(const char* binary_name, const char* pattern,
172+
s2binlib_pattern_scan_callback callback, void* user_data);
173+
85174
/**
86175
* Find a vtable by class name in the specified binary
87176
*

vendor/s2binlib/s2binlib.lib

69.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)