source: Daodan/src/Daodan_Utility.c@ 782

Last change on this file since 782 was 692, checked in by alloc, 12 years ago

Daodan: Lots of cleanups (mostly unnecessary includes removed, empty files deleted, case of filenames corrected)

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