source: Daodan/src/Daodan_Utility.c@ 679

Last change on this file since 679 was 677, checked in by alloc, 12 years ago

Daodan: Updated src to work with MinGW

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