Skip to content

Commit b21b08f

Browse files
author
tobii-dev
committed
added laps cmd, removed .ini stuff
1 parent bee9bc8 commit b21b08f

File tree

9 files changed

+140
-56
lines changed

9 files changed

+140
-56
lines changed

data/cfg.ini

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
[GFX]
2-
boolForceWindowedMode = 0
1+
[NAME]
2+
name = "YOUR_NAME_HERE"
33

44
[FPS]
55
intFPSLimit = 31
66

7-
[NAME]
8-
name = "YOUR_NAME_HERE"

source/blur.cpp

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ gameAPI::gameAPI(uintptr_t p) : config("cfg.ini") {
2424
moduleBase = p;
2525
}
2626

27+
28+
uint8_t gameAPI::lobby_get_laps() {
29+
uint8_t laps = *(uint8_t*) (moduleBase + ADDY_LAN_LAPS_LOBBY);
30+
return laps;
31+
}
32+
33+
bool gameAPI::lobby_set_laps(uint8_t laps) {
34+
bool ok = false;
35+
*(uint8_t*)(moduleBase + ADDY_LAN_LAPS_LOBBY) = laps;
36+
*(uint8_t*)(moduleBase + ADDY_LAN_LAPS_READ) = laps;
37+
ok = true;
38+
39+
return ok;
40+
}
41+
42+
2743
uintptr_t gameAPI::lobby_entlist_get_first_player() {
2844
uintptr_t addr = moduleBase + ADDY_LAN_PLAYERS_LL_PTR;
2945

@@ -35,23 +51,18 @@ uintptr_t gameAPI::lobby_entlist_get_first_player() {
3551
return addr;
3652
}
3753

38-
3954
uintptr_t gameAPI::get_next_player(uintptr_t p) {
4055
uintptr_t addr = *(uintptr_t*) (p+OFFSET_PLAYER_NEXT);
4156
return addr;
4257
}
4358

44-
4559
std::string gameAPI::lobby_get_player_name(uintptr_t p) {
4660
std::string name = "";
4761
short* ptr = ((short*)(p + OFFSET_PLAYER_NAME));
48-
char c = NULL;
49-
do {
50-
c = (char) *ptr;
62+
while (*ptr != NULL) {
63+
name += (unsigned char) *ptr;
5164
ptr++;
52-
name += c;
53-
54-
} while (c != NULL);
65+
}
5566
return name;
5667
}
5768

@@ -119,21 +130,22 @@ std::string gameAPI::lobby_get_player_green_mod_as_string(uintptr_t p) {
119130
return str;
120131
}
121132

122-
//TODO: lets have all the init code here
133+
134+
//TODO: lets have "ALL" the init code here
123135
void gameAPI::load() {
124136
console.start();
125137
if (install_username_hook()) blurAPI->console.print("set_usr_hook() -> true");
126138
//if (!install_menu_hook()) blurAPI->console.print("ERROR in gameAPI::load() [install_menu_hook() returned false]");
127139
}
128140

129-
130141
void gameAPI::unload() {
131142
//TODO: unhooks
132143
console.close();
133144
}
134145

135146

136147
//TODO: move this somewhere sane
148+
//TODO: add indicator to see what is currently set
137149
bool gameAPI::toggle_drifter_mod_SP() {
138150
uintptr_t modAdr = moduleBase + ADDY_SP_MOD;
139151
int* modPtr = (int*) modAdr;
@@ -154,11 +166,15 @@ bool gameAPI::toggle_drifter_mod_SP() {
154166
bool gameAPI::set_name_LAN(std::string szName) {
155167
bool set = false;
156168
int len = szName.length();
157-
if (len && (len <= LEN_LAN_NAME)) {
158-
uintptr_t nameAdr = moduleBase + ADDY_LAN_NAME;
159-
short* ptr = (short*) nameAdr;
160-
for (int i=0; i<len; i++) ptr[i] = szName[i];
161-
ptr[len] = NULL;
169+
if ((0<=len) && (len<=LEN_LAN_NAME)) {
170+
short* namePtr = (short*)(moduleBase + ADDY_LAN_NAME);
171+
short* dispPtr = (short*)(moduleBase + ADDY_DISP_NAME);
172+
for (int i = 0; i < len; i++) {
173+
namePtr[i] = szName[i];
174+
dispPtr[i] = szName[i];
175+
}
176+
namePtr[len] = NULL;
177+
dispPtr[len] = NULL;
162178
set = true;
163179
}
164180
return set;

source/blur.h

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include "blur_hooks.h"
77
#include "mem.h"
88

9+
910
enum BLUR_MOD_ID {
10-
//Y
11+
//Yellow
1112
IRON_FIST = 0,
1213
JUMP_THE_GUN,
1314
FRONT_RUNNER,
@@ -16,7 +17,7 @@ enum BLUR_MOD_ID {
1617
SHOWY_FLOURISH,
1718
STABLE_FRAME,
1819
BATTERING_RAM,
19-
//O
20+
//Orange
2021
DECOY_DROP,
2122
MAGNETIC_FIELD,
2223
SCRAMBLER,
@@ -25,7 +26,7 @@ enum BLUR_MOD_ID {
2526
ADAPTIVE_SHIELDING,
2627
SAFETY_NET,
2728
SHIELDED_BAY,
28-
//G
29+
//Green
2930
ECM,
3031
VAMPIRIC_WRECK,
3132
BRIBE,
@@ -43,7 +44,6 @@ enum BLUR_MOD_ID {
4344
ARMOR_PLATING,
4445
SCATTER_SHOT,
4546
SUPER_SHUNT,
46-
4747
//aux
4848
MOD_ID_MAX
4949
};
@@ -58,7 +58,6 @@ const char * const BLUR_MOD_NAMES[] = {
5858
"(y) SHOWY FLOURISH",
5959
"(y) STABLE FRAME",
6060
"(y) BATTERING RAM",
61-
6261
"(o) DECOY DROP",
6362
"(o) MAGNETIC FIELD",
6463
"(o) SCRAMBLER",
@@ -67,7 +66,6 @@ const char * const BLUR_MOD_NAMES[] = {
6766
"(o) ADAPTIVE SHIELDING",
6867
"(o) SAFETY NET",
6968
"(o) SHIELDED BAY",
70-
7169
"(g) ECM",
7270
"(g) VAMPIRIC WRECK",
7371
"(g) BRIBE",
@@ -76,7 +74,6 @@ const char * const BLUR_MOD_NAMES[] = {
7674
"(g) SILENT RUNNING",
7775
"(g) LAST GASP",
7876
"(g) MASTERMINE",
79-
8077
"(SP) QUADSHOCK",
8178
"(SP) OVERBOLT",
8279
"(SP) TITANIUM SHIELD",
@@ -86,40 +83,18 @@ const char * const BLUR_MOD_NAMES[] = {
8683
"(SP) SCATTER SHOT",
8784
"(SP) SUPER SHUNT"
8885
};
89-
/* // for "old" blur version"
90-
#define ADDY_LAN_MOD_YELLOW 0xE12F84
91-
#define ADDY_LAN_MOD_ORANGE 0xE12F88
92-
#define ADDY_LAN_MOD_GREENY 0xE12F8C
93-
#define ADDY_SP_MOD 0xE14240
94-
95-
#define ADDY_LAN_NAME 0xCE5898
96-
#define LEN_LAN_NAME 32
9786

9887

99-
#define ADDY_UNLOCK_INPUT 0xCC221C
100-
#define OFFSETS_UNLOCK_INPUT {0x14, 0x35C, 0xC, 0x4B0}
101-
102-
*/
103-
104-
//for "new" (discord) blur version:
10588
#define ADDY_LAN_MOD_YELLOW 0xE142DC
10689
#define ADDY_LAN_MOD_ORANGE 0xE142E0
10790
#define ADDY_LAN_MOD_GREENY 0xE142E4
10891
#define ADDY_SP_MOD 0xE15598
10992

11093

111-
// "new" = "old" + 0x1290
11294
#define ADDY_LAN_NAME 0xCE6B28
95+
#define ADDY_DISP_NAME 0xDA8878
11396
#define LEN_LAN_NAME 32
11497

115-
//TODO
116-
#define ADDY_UNLOCK_INPUT 0xCC221C
117-
118-
//hope?
119-
#define OFFSETS_UNLOCK_INPUT {0x14, 0x35C, 0xC, 0x4B0}
120-
121-
//"old"entlist start
122-
//0xDB31D8 @ {18}
12398

12499
// TODO elaborate info:
125100
//addy of player_0 = value of whatever is @ [ [@base]+0x18 ]
@@ -136,6 +111,11 @@ const char * const BLUR_MOD_NAMES[] = {
136111
#define OFFSET_PLAYER_MOD_G 0x158
137112

138113

114+
// what the user sees as laps
115+
#define ADDY_LAN_LAPS_READ 0xE3E8F9
116+
//what the rest of the lobby sees
117+
#define ADDY_LAN_LAPS_LOBBY 0xE3923B
118+
139119

140120
struct gameConfig {
141121
std::string user_name;
@@ -156,6 +136,8 @@ struct gameAPI {
156136
void unload();
157137
gameAPI(uintptr_t p);
158138

139+
uint8_t lobby_get_laps();
140+
bool lobby_set_laps(uint8_t laps);
159141
std::string lobby_get_player_name(uintptr_t p);
160142
std::string lobby_get_player_mods_as_string(uintptr_t p);
161143
std::string lobby_get_player_yellow_mod_as_string(uintptr_t p);

source/blur_console.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ void gameConsole::start() {
6969
HANDLE input_thread_handle = CreateThread(NULL, 0, input_thread, input, 0, NULL);
7070
}
7171

72-
7372
void gameConsole::close() {
7473
print("Closing console..."); // might not get printed
7574
FreeConsole();
@@ -129,14 +128,37 @@ bool gameConsole::cmd_handler(std::string cmd) {
129128
while (p != NULL) {
130129
//TODO format & colours
131130
print("\tNAME: \"" + blurAPI->lobby_get_player_name(p) + "\"");
132-
//print("\t\tMODS: " + blurAPI->lobby_get_player_mods_as_string(p));
133131
print("\t MODS:");
134132
print("\t\t\t" + blurAPI->lobby_get_player_yellow_mod_as_string(p));
135133
print("\t\t\t" + blurAPI->lobby_get_player_orange_mod_as_string(p));
136134
print("\t\t\t" + blurAPI->lobby_get_player_green_mod_as_string(p));
137135
p = blurAPI->get_next_player(p);
138136
}
139137
isCmd = true;
138+
} else if (cmd_args[0] == "laps") {
139+
int argsc = cmd_args.size();
140+
//FIXME there HAS to be a more elegant way to do this, maybe by hooking the verify function...
141+
if (argsc == 1) {
142+
print("LAPS: OFF" );
143+
restore_lobby_laps_func();
144+
print("\tEnter and exit the lobby settings menu to apply.");
145+
//let the player reset them from the game settings
146+
} else if (argsc == 2) {
147+
int laps = atoi(cmd_args[1].c_str());
148+
if ((9<laps) && (laps<256)) {
149+
//TODO patch verify func
150+
patch_lobby_laps_func();
151+
//set lobby laps to laps
152+
blurAPI->lobby_set_laps((uint8_t)laps);
153+
print("LAPS: " + std::to_string(laps));
154+
//tell them to open and close the menu
155+
print("\tEnter and exit the lobby settings menu to apply this change to other players.");
156+
} else {
157+
print("\t*Error*(We want more laps!) USAGE: laps <10..255>)");
158+
}
159+
} else {
160+
print("\t*Error*(Too many args! (" + std::to_string(argsc) + ")) USAGE: laps <10..255>)");
161+
}
140162
}
141163
}
142164
return isCmd;

source/blur_hooks.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ bool install_username_hook() {
5353
}
5454

5555

56-
5756
bool __stdcall hook_GetUserNameA(char* buff, unsigned long * len) {
5857
//bool r = GetUserNameA(buff, len); //original func
5958
bool r = true;
@@ -62,11 +61,55 @@ bool __stdcall hook_GetUserNameA(char* buff, unsigned long * len) {
6261
for (int i=0; i<n; i++) buff[i] = name[i];
6362
buff[n] = NULL;
6463
*len = n;
65-
blurAPI->console.print("Name set to: " + name);
64+
blurAPI->console.print("Name set to: \"" + name + "\"");
6665
return r;
6766
}
6867

6968

69+
bool patch_lobby_laps_func() {
70+
bool ok = false;
71+
//TODO (consider using) mem.h <> set_nops(adr, len)
72+
73+
void* dst = (void*) (blurAPI->moduleBase + FUNC_SET_LOBBY_LAPS_ADDY);
74+
uint8_t* addy = (uint8_t*)dst;
75+
DWORD org, _;
76+
VirtualProtect(dst, FUNC_SET_LOBBY_LAPS_INS_LEN, PAGE_EXECUTE_READWRITE, &org);
77+
/* Debug stuffs
78+
unsigned char c;
79+
c = addy[0];
80+
blurAPI->console.print("addy0=" + std::to_string(c) + "");
81+
c = addy[1];
82+
blurAPI->console.print("addy1=" + std::to_string(c) + "");
83+
*/
84+
if ((addy[0] == FUNC_SET_LOBBY_LAPS_INS_BYTE0) && (addy[1] == FUNC_SET_LOBBY_LAPS_INS_BYTE1)) {
85+
ok = true; //we actually patched something
86+
//indicate patched function?
87+
}
88+
addy[0] = OP_NOP;
89+
addy[1] = OP_NOP;
90+
VirtualProtect(dst, FUNC_SET_LOBBY_LAPS_INS_LEN, org, &_);
91+
92+
return ok;
93+
}
94+
95+
bool restore_lobby_laps_func() {
96+
bool ok = false; //FIXME check if noped?
97+
98+
void* dst = (void*) (blurAPI->moduleBase + FUNC_SET_LOBBY_LAPS_ADDY);
99+
uint8_t* addy = (uint8_t*)dst;
100+
DWORD org, _;
101+
VirtualProtect(dst, FUNC_SET_LOBBY_LAPS_INS_LEN, PAGE_EXECUTE_READWRITE, &org);
102+
if ((addy[0] == OP_NOP) && (addy[1] == OP_NOP)) {
103+
ok = true; //we actually "did" something
104+
//TODO indicate we did someting
105+
}
106+
addy[0] = FUNC_SET_LOBBY_LAPS_INS_BYTE0;
107+
addy[1] = FUNC_SET_LOBBY_LAPS_INS_BYTE1;
108+
VirtualProtect(dst, FUNC_SET_LOBBY_LAPS_INS_LEN, org, &_);
109+
110+
return ok;
111+
}
112+
70113

71114
//TODO: debug stuff
72115
//https://en.wikibooks.org/wiki/X86_Assembly/X86_Architecture

source/blur_hooks.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
#define HOOK_MENU_FUNC_INS_LEN 6
77

88
//winapi32 call to GetUserNameA() hook here
9-
//#define HOOK_NAME_FUNC_ADDY 0x95CD2A
10-
//in1.2:
119
#define HOOK_NAME_FUNC_ADDY 0x95E0EA
1210
#define HOOK_NAME_FUNC_INS_LEN 6
1311

12+
13+
// mov [edi], al //gets EDI ptr register from some odd func earlier (im too dumb to dive into it)
14+
#define FUNC_SET_LOBBY_LAPS_ADDY 0x6F41B2
15+
#define FUNC_SET_LOBBY_LAPS_INS_LEN 0x2
16+
#define FUNC_SET_LOBBY_LAPS_INS_BYTE0 0x88
17+
#define FUNC_SET_LOBBY_LAPS_INS_BYTE1 0x07
18+
1419
struct gameHooks {
1520
fn_ptr_t fn_menu_trampoline = nullptr;
1621
fn_ptr_t fn_menu_callback = nullptr;
@@ -27,5 +32,7 @@ void fn_hello_world();
2732
bool install_username_hook();
2833
bool __stdcall hook_GetUserNameA(char* buff, unsigned long *len);
2934

35+
bool patch_lobby_laps_func();
36+
bool restore_lobby_laps_func();
3037

3138
//void aux_print_registers();

source/d3d9.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ HRESULT f_IDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS *pPresentationParameters
138138
// NOTE: call onLostDevice for custom D3D components here.
139139

140140
HRESULT hr = f_pD3DDevice->Reset(pPresentationParameters);
141-
blurAPI->console.print("\tf_pD3DDevice->Reset(pPresentationParameters)");
141+
//blurAPI->console.print("\tf_pD3DDevice->Reset(pPresentationParameters)");
142142

143143
// NOTE: call onResetDevice for custom D3D components here.
144144

source/mem.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,17 @@ bool __stdcall set_call_func(void* src, fn_ptr_t f) {
7373
}
7474
return ok;
7575
}
76+
77+
78+
bool set_nops(void* dst, unsigned int len) {
79+
bool ok = false;
80+
if ((len > 0) && (dst != NULL)) {
81+
DWORD org, _;
82+
uint8_t* ptr = (uint8_t*) dst;
83+
VirtualProtect(dst, len, PAGE_EXECUTE_READWRITE, &org);
84+
for (unsigned int i = 0; i < len; i++) ptr[i] = OP_NOP;
85+
VirtualProtect(dst, len, org, &_);
86+
ok = true;
87+
}
88+
return ok;
89+
}

0 commit comments

Comments
 (0)