1 |
#include <windows.h> |
2 |
#include <stdlib.h> |
3 |
#include <stdarg.h> |
4 |
#include <stdint.h> |
5 |
#include "oni_stdio.h" |
6 |
|
7 |
#include "Daodan_Utility.h" |
8 |
#include "BFW_Utility.h" |
9 |
#include "Oni.h" |
10 |
|
11 |
const double fps = 60.0; |
12 |
|
13 |
void __cdecl DDrStartupMessage(const char* fmt, ...) |
14 |
{ |
15 |
va_list ap; |
16 |
va_start(ap, fmt); |
17 |
char* buffer = malloc(vsnprintf(NULL, 0, fmt, ap) + 1); |
18 |
|
19 |
vsprintf(buffer, fmt, ap); |
20 |
va_end(ap); |
21 |
|
22 |
if (!ONgFileStartup) |
23 |
if (!(ONgFileStartup = oni_fopen("startup.txt", "w"))) |
24 |
return; |
25 |
|
26 |
oni_fprintf(ONgFileStartup, "%s\n", buffer); |
27 |
free(buffer); |
28 |
|
29 |
oni_fflush(ONgFileStartup); |
30 |
return; |
31 |
} |
32 |
|
33 |
/* |
34 |
int64_t ONICALL DDrMachineTime_Sixtieths() |
35 |
{ |
36 |
static int64_t LastTime, Time; |
37 |
int64_t Current; |
38 |
|
39 |
Current = LastTime + GetTickCount(); |
40 |
|
41 |
if (Current > Time) |
42 |
{ |
43 |
LastTime += 1; |
44 |
Current += 1; |
45 |
} |
46 |
|
47 |
Time = Current; |
48 |
|
49 |
return (Time * 3) / 50; |
50 |
} |
51 |
*/ |
52 |
|
53 |
int64_t ONICALL DDrMachineTime_Sixtieths() |
54 |
{ |
55 |
static uint32_t startticks = 0; |
56 |
double ticks = 0; |
57 |
|
58 |
if (startticks) |
59 |
ticks = GetTickCount() - startticks; |
60 |
else |
61 |
startticks = GetTickCount(); |
62 |
|
63 |
return (int64_t)(ticks / 1000.0 * fps); |
64 |
} |
65 |
|
66 |
int64_t ONICALL DDrMachineTime_High() |
67 |
{ |
68 |
// LARGE_INTEGER PerfCount; |
69 |
// |
70 |
// if (!QueryPerformanceCounter(&PerfCount)) |
71 |
// PerfCount.QuadPart = GetTickCount(); |
72 |
// |
73 |
// return PerfCount.QuadPart; |
74 |
return GetTickCount(); |
75 |
} |
76 |
|
77 |
double ONICALL DDrMachineTime_High_Frequency() |
78 |
{ |
79 |
// LARGE_INTEGER Frequency; |
80 |
// |
81 |
// if (!QueryPerformanceFrequency(&Frequency)) |
82 |
return 1000.0; |
83 |
|
84 |
// return Frequency.QuadPart; |
85 |
} |
86 |
|
87 |
void ONICALL DDrWeapon2Message(int* weapon, void* output_ptr) { |
88 |
char buffer[128] = {0}; |
89 |
char* weapon_string = (char*)(*(weapon + 1)+0x5C); |
90 |
int16_t ammo = *(int16_t *)((int)weapon + 0x56); |
91 |
int16_t maxammo = *(int16_t *)(*(weapon + 1)+0xC0); |
92 |
float ratio = (float)ammo / (float)maxammo; |
93 |
char ammocolor = ' '; |
94 |
if(ratio >= .9) ammocolor = 'g'; |
95 |
else if (ratio >= .5) ammocolor = 'y'; |
96 |
else if (ratio >= .2) ammocolor = 'o'; |
97 |
else ammocolor = 'r'; |
98 |
DDrMake_Weapon_Message( weapon_string, buffer); //gets the name of the weapon and formats it...probably doesn't need to be in seperate func. |
99 |
sprintf(SSrMessage_Find("autoprompt_weapon"), "%s |[%s.%i/%i]|", buffer, &ammocolor, ammo, maxammo); //copies the new string to ONGS |
100 |
ONiGameState_FindAutoPromptMessage("weapon", output_ptr); //does what the code i replaced does. Basically tells the game to show the msg. |
101 |
} |
102 |
|
103 |
|
104 |
void ONICALL DDrMake_Weapon_Message(char* weapon_string, char* output_ptr) { |
105 |
char* weapon_msg = NULL; //The normal "You have recieved X" message. |
106 |
char weapon_name[64] = {'\0'}; //The stripped weapon name |
107 |
//TODO, someday: dynamically detect different keybindings. |
108 |
char default_msg[] = "Press [c.Q] to pick up weapon."; //default return |
109 |
|
110 |
//Find the recieved message string |
111 |
weapon_msg = SSrMessage_Find(weapon_string); |
112 |
//this probably could be reorganized |
113 |
if(weapon_msg) { //SSrMsgblah returns NULL if it can't find the message key |
114 |
memcpy(weapon_name, weapon_msg, (strstr(weapon_msg," received.") - weapon_msg )); //strips uneeded characters |
115 |
sprintf(output_ptr, "Press [c.Q] to pick up %s", weapon_name); |
116 |
} |
117 |
else { |
118 |
memcpy(output_ptr, default_msg, sizeof(default_msg)); |
119 |
} |
120 |
|
121 |
} |