source: Daodan/MSVC/Daodan_Utility.c@ 619

Last change on this file since 619 was 589, checked in by gumby, 13 years ago

stuff

File size: 5.0 KB
Line 
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
13const double fps = 60.0;
14
15void __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/*
39int64_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
58int64_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
71int64_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
82double 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
92void 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 if (ratio >= .9) ammocolor = 'g';
102 else if (ratio >= .5) ammocolor = 'y';
103 else if (ratio >= .2) ammocolor = 'o';
104 else ammocolor = 'r';
105
106 DDrMake_Weapon_Message( weapon_string, buffer); //gets the name of the weapon and formats it...probably doesn't need to be in seperate func.
107 sprintf(SSrMessage_Find("autoprompt_weapon"), "%s |[%c.%i/%i]|", buffer, ammocolor, ammo, maxammo); //copies the new string to ONGS
108 ONiGameState_FindAutoPromptMessage("weapon", output_ptr); //does what the code i replaced does. Basically tells the game to show the msg.
109}
110
111
112void ONICALL DDrMake_Weapon_Message(char* weapon_string, char* output_ptr)
113{
114 char* weapon_msg = NULL; //The normal "You have recieved X" message.
115 char weapon_name[64] = {'\0'}; //The stripped weapon name
116 //TODO, someday: dynamically detect different keybindings.
117 char default_msg[] = "Press [c.Q] to pick up weapon."; //default return
118
119 //Find the recieved message string
120 weapon_msg = SSrMessage_Find(weapon_string);
121 //this probably could be reorganized
122 if(weapon_msg) { //SSrMsgblah returns NULL if it can't find the message key
123 memcpy(weapon_name, weapon_msg, (strstr(weapon_msg,"] ") - weapon_msg + 1)); //strips uneeded characters
124 sprintf(output_ptr, "Press [c.Q] to pick up %s", weapon_name);
125 }
126 else {
127 memcpy(output_ptr, default_msg, sizeof(default_msg));
128 }
129
130}
131
132typedef struct
133{
134 uint16_t x;
135 uint16_t y;
136
137} IMtPoint2D;
138IMtPoint2D Point = {256, 250};
139extern void* TSrTest;
140extern void* TSrScores;
141unsigned int lastPasteTime;
142
143//TODO: Fix what happens when you hold down paste
144//Check if console is open
145void DDrPasteHack()
146{
147 COtTextArea* cons = *(COtTextArea**)0x00571B74;
148 char* clipboardText = 0;
149 if(ONgGameState->Input.Current.Actions1 & Action_Console && GetKeyState(0x56) & 0x80 && GetKeyState(VK_CONTROL) & 0x80 )
150 {
151 if(cons && cons->text_entries && cons->num_text_entries)
152 {
153 //why abs()? so we dont have to reset the timer after a level load.
154 if( abs(ONgGameState->GameTime - lastPasteTime) > 60) {
155 //DDrConsole_Print(cons->text_entries[0].text);
156 if(OpenClipboard(ONgPlatformData.Window))
157 {
158 unsigned short charsUsed = strlen(cons->text_entries[0].text);
159 //get rid of the v character
160 if(charsUsed) charsUsed--;
161 clipboardText = GetClipboardData(CF_TEXT);
162 if(clipboardText && strlen(clipboardText) + charsUsed < 502)
163 {
164 strcpy_s( cons->text_entries[0].text + charsUsed, 502 - charsUsed - 1, clipboardText);
165 lastPasteTime = ONgGameState->GameTime;
166 }
167 CloseClipboard();
168 }
169
170 }
171 else
172 {
173 //need to hook whatever controls however often you can repeat characters...i guess.
174 //cons->text_entries[0].text[strlen(cons->text_entries[0].text) - 1] = 0;
175 }
176 }
177 }
178}
179
180void ONICALL DDrText_Hook()
181{
182
183 if(TSrTest)
184 {
185 TSrContext_DrawText(TSrTest, "FINALLY THIS BLOODY TEXT THING WORKS\n Gotta call it at the right point...", 128, 0, &Point);
186
187 }
188 if(server_started || client_connected)
189 {
190 FLrRun_Scores();
191 }
192 else if( MsNet_Running )
193 {
194 MSNet_DrawGames();
195 }
196
197
198 DDrPasteHack();
199
200 COrConsole_StatusLine_Display();
201
202}
Note: See TracBrowser for help on using the repository browser.