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 | #include "Flatline_Public.h"
|
---|
11 | #include "Mariusnet_Public.h"
|
---|
12 |
|
---|
13 | const double fps = 60.0;
|
---|
14 |
|
---|
15 | void __cdecl DDrStartupMessage(const char* fmt, ...)
|
---|
16 | {
|
---|
17 |
|
---|
18 | char* buffer;
|
---|
19 | va_list ap;
|
---|
20 | va_start(ap, fmt);
|
---|
21 |
|
---|
22 | buffer = malloc(vsnprintf(NULL, 0, fmt, ap) + 1);
|
---|
23 |
|
---|
24 | vsprintf(buffer, fmt, ap);
|
---|
25 | va_end(ap);
|
---|
26 |
|
---|
27 | if (!ONgFileStartup)
|
---|
28 | if (!(ONgFileStartup = oni_fopen("startup.txt", "w")))
|
---|
29 | return;
|
---|
30 |
|
---|
31 | oni_fprintf(ONgFileStartup, "%s\n", buffer);
|
---|
32 | free(buffer);
|
---|
33 |
|
---|
34 | oni_fflush(ONgFileStartup);
|
---|
35 | return;
|
---|
36 | }
|
---|
37 |
|
---|
38 | /*
|
---|
39 | int64_t ONICALL DDrMachineTime_Sixtieths()
|
---|
40 | {
|
---|
41 | static int64_t LastTime, Time;
|
---|
42 | int64_t Current;
|
---|
43 |
|
---|
44 | Current = LastTime + GetTickCount();
|
---|
45 |
|
---|
46 | if (Current > Time)
|
---|
47 | {
|
---|
48 | LastTime += 1;
|
---|
49 | Current += 1;
|
---|
50 | }
|
---|
51 |
|
---|
52 | Time = Current;
|
---|
53 |
|
---|
54 | return (Time * 3) / 50;
|
---|
55 | }
|
---|
56 | */
|
---|
57 |
|
---|
58 | int64_t ONICALL DDrMachineTime_Sixtieths()
|
---|
59 | {
|
---|
60 | static uint32_t startticks = 0;
|
---|
61 | double ticks = 0;
|
---|
62 |
|
---|
63 | if (startticks)
|
---|
64 | ticks = GetTickCount() - startticks;
|
---|
65 | else
|
---|
66 | startticks = GetTickCount();
|
---|
67 |
|
---|
68 | return (int64_t)(ticks / 1000.0 * fps);
|
---|
69 | }
|
---|
70 |
|
---|
71 | int64_t ONICALL DDrMachineTime_High()
|
---|
72 | {
|
---|
73 | // LARGE_INTEGER PerfCount;
|
---|
74 | //
|
---|
75 | // if (!QueryPerformanceCounter(&PerfCount))
|
---|
76 | // PerfCount.QuadPart = GetTickCount();
|
---|
77 | //
|
---|
78 | // return PerfCount.QuadPart;
|
---|
79 | return GetTickCount();
|
---|
80 | }
|
---|
81 |
|
---|
82 | double ONICALL DDrMachineTime_High_Frequency()
|
---|
83 | {
|
---|
84 | // LARGE_INTEGER Frequency;
|
---|
85 | //
|
---|
86 | // if (!QueryPerformanceFrequency(&Frequency))
|
---|
87 | return 1000.0;
|
---|
88 |
|
---|
89 | // return Frequency.QuadPart;
|
---|
90 | }
|
---|
91 |
|
---|
92 | void ONICALL DDrWeapon2Message(int* weapon, void* output_ptr)
|
---|
93 | {
|
---|
94 | char buffer[128] = {0};
|
---|
95 | char* weapon_string = (char*)(*(weapon + 1)+0x5C);
|
---|
96 | int16_t ammo = *(int16_t *)((int)weapon + 0x56);
|
---|
97 | int16_t maxammo = *(int16_t *)(*(weapon + 1)+0xC0);
|
---|
98 | float ratio = (float)ammo / (float)maxammo;
|
---|
99 |
|
---|
100 | char ammocolor;
|
---|
101 |
|
---|
102 | if (ratio >= .9) ammocolor = 'g';
|
---|
103 | else if (ratio >= .5) ammocolor = 'y';
|
---|
104 | else if (ratio >= .2) ammocolor = 'o';
|
---|
105 | else ammocolor = 'r';
|
---|
106 |
|
---|
107 | DDrMake_Weapon_Message( weapon_string, buffer); //gets the name of the weapon and formats it...probably doesn't need to be in seperate func.
|
---|
108 | sprintf(SSrMessage_Find("autoprompt_weapon"), "%s |[%c.%i/%i]|", buffer, ammocolor, ammo, maxammo); //copies the new string to ONGS
|
---|
109 | ONiGameState_FindAutoPromptMessage("weapon", output_ptr); //does what the code i replaced does. Basically tells the game to show the msg.
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | void ONICALL DDrMake_Weapon_Message(char* weapon_string, char* output_ptr)
|
---|
114 | {
|
---|
115 | char* weapon_msg = NULL; //The normal "You have recieved X" message.
|
---|
116 | char weapon_name[64] = {'\0'}; //The stripped weapon name
|
---|
117 | //TODO, someday: dynamically detect different keybindings.
|
---|
118 | char default_msg[] = "Press [c.Q] to pick up weapon."; //default return
|
---|
119 |
|
---|
120 | //Find the recieved message string
|
---|
121 | weapon_msg = SSrMessage_Find(weapon_string);
|
---|
122 | //this probably could be reorganized
|
---|
123 | if(weapon_msg) { //SSrMsgblah returns NULL if it can't find the message key
|
---|
124 | memcpy(weapon_name, weapon_msg, (strstr(weapon_msg,"] ") - weapon_msg + 1)); //strips uneeded characters
|
---|
125 | sprintf(output_ptr, "Press [c.Q] to pick up %s", weapon_name);
|
---|
126 | }
|
---|
127 | else {
|
---|
128 | memcpy(output_ptr, default_msg, sizeof(default_msg));
|
---|
129 | }
|
---|
130 |
|
---|
131 | }
|
---|
132 |
|
---|
133 | typedef struct
|
---|
134 | {
|
---|
135 | uint16_t x;
|
---|
136 | uint16_t y;
|
---|
137 |
|
---|
138 | } IMtPoint2D;
|
---|
139 | IMtPoint2D Point = {256, 250};
|
---|
140 | extern void* TSrTest;
|
---|
141 | extern void* TSrScores;
|
---|
142 | unsigned int lastPasteTime;
|
---|
143 |
|
---|
144 | //TODO: Fix what happens when you hold down paste
|
---|
145 | //Check if console is open
|
---|
146 | void DDrPasteHack()
|
---|
147 | {
|
---|
148 | COtTextArea* cons = *(COtTextArea**)0x00571B74;
|
---|
149 | char* clipboardText = 0;
|
---|
150 | if(ONgGameState->Input.Current.Actions1 & Action_Console && GetKeyState(0x56) & 0x80 && GetKeyState(VK_CONTROL) & 0x80 )
|
---|
151 | {
|
---|
152 | if(cons && cons->text_entries && cons->num_text_entries)
|
---|
153 | {
|
---|
154 | //why abs()? so we dont have to reset the timer after a level load.
|
---|
155 | if( abs(ONgGameState->GameTime - lastPasteTime) > 60) {
|
---|
156 | //DDrConsole_Print(cons->text_entries[0].text);
|
---|
157 | if(OpenClipboard(ONgPlatformData.Window))
|
---|
158 | {
|
---|
159 | unsigned short charsUsed = strlen(cons->text_entries[0].text);
|
---|
160 | //get rid of the v character
|
---|
161 | if(charsUsed) charsUsed--;
|
---|
162 | clipboardText = GetClipboardData(CF_TEXT);
|
---|
163 | if(clipboardText && strlen(clipboardText) + charsUsed < 502)
|
---|
164 | {
|
---|
165 | strcpy_s( cons->text_entries[0].text + charsUsed, 502 - charsUsed - 1, clipboardText);
|
---|
166 | lastPasteTime = ONgGameState->GameTime;
|
---|
167 | }
|
---|
168 | CloseClipboard();
|
---|
169 | }
|
---|
170 |
|
---|
171 | }
|
---|
172 | else
|
---|
173 | {
|
---|
174 | //need to hook whatever controls however often you can repeat characters...i guess.
|
---|
175 | //cons->text_entries[0].text[strlen(cons->text_entries[0].text) - 1] = 0;
|
---|
176 | }
|
---|
177 | }
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | void ONICALL DDrText_Hook()
|
---|
182 | {
|
---|
183 |
|
---|
184 | if(TSrTest)
|
---|
185 | {
|
---|
186 | TSrContext_DrawText(TSrTest, "FINALLY THIS BLOODY TEXT THING WORKS\n Gotta call it at the right point...", 128, 0, &Point);
|
---|
187 |
|
---|
188 | }
|
---|
189 | if(server_started || client_connected)
|
---|
190 | {
|
---|
191 | FLrRun_Scores();
|
---|
192 | }
|
---|
193 | else if( MsNet_Running )
|
---|
194 | {
|
---|
195 | MSNet_DrawGames();
|
---|
196 | }
|
---|
197 |
|
---|
198 |
|
---|
199 | DDrPasteHack();
|
---|
200 |
|
---|
201 | COrConsole_StatusLine_Display();
|
---|
202 |
|
---|
203 | }
|
---|