source: Daodan/src/Patches/Utility.c@ 1164

Last change on this file since 1164 was 1163, checked in by rossy, 3 years ago

Daodan: Add new local input system based on Raw Input

File size: 4.4 KB
RevLine 
[994]1#include <windows.h>
2#include <stdlib.h>
3#include <stdarg.h>
4
5#include "Utility.h"
6#include "../Oni/Oni.h"
7
8const double fps = 60.0;
9
10void __cdecl DDrStartupMessage(const char* fmt, ...)
11{
12
13 char* buffer;
14 va_list ap;
15 va_start(ap, fmt);
16
17 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
33int64_t ONICALL DDrMachineTime_Sixtieths()
34{
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
46int64_t ONICALL DDrMachineTime_High()
47{
48// LARGE_INTEGER PerfCount;
49//
50// if (!QueryPerformanceCounter(&PerfCount))
51// PerfCount.QuadPart = GetTickCount();
52//
53// return PerfCount.QuadPart;
54 return GetTickCount();
55}
56
57double ONICALL DDrMachineTime_High_Frequency()
58{
59// LARGE_INTEGER Frequency;
60//
61// if (!QueryPerformanceFrequency(&Frequency))
62 return 1000.0;
63
64// return Frequency.QuadPart;
65}
66
67void ONICALL DDrWeapon2Message(int* weapon, void* output_ptr)
68{
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;
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
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.
82 sprintf(SSrMessage_Find("autoprompt_weapon"), "%s |[%c.%i/%i]|", buffer, ammocolor, ammo, maxammo); //copies the new string to ONGS
83 ONiGameState_FindAutoPromptMessage("weapon", output_ptr); //does what the code i replaced does. Basically tells the game to show the msg.
84}
85
86
87void ONICALL DDrMake_Weapon_Message(char* weapon_string, char* output_ptr)
88{
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
98 memcpy(weapon_name, weapon_msg, (strstr(weapon_msg,"] ") - weapon_msg + 1)); //strips uneeded characters
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 }
[1163]104
[994]105}
106
[1163]107IMtPoint Point = {256, 250};
[994]108extern void* TSrTest;
109extern void* TSrScores;
110unsigned int lastPasteTime;
111
112//TODO: Fix what happens when you hold down paste
113//Check if console is open
114void DDrPasteHack()
115{
116 COtTextArea* cons = *(COtTextArea**)0x00571B74;
117 char* clipboardText = 0;
[1161]118 if(ONgGameState->Input.ActionsDown & Action_Console && GetKeyState(0x56) & 0x80 && GetKeyState(VK_CONTROL) & 0x80 )
[994]119 {
120 if(cons && cons->text_entries && cons->num_text_entries)
121 {
122 //why abs()? so we dont have to reset the timer after a level load.
123 if( abs(ONgGameState->GameTime - lastPasteTime) > 60) {
124 //DDrConsole_Print(cons->text_entries[0].text);
125 if(OpenClipboard(ONgPlatformData.Window))
126 {
127 unsigned short charsUsed = strlen(cons->text_entries[0].text);
128 //get rid of the v character
129 if(charsUsed) charsUsed--;
130 clipboardText = GetClipboardData(CF_TEXT);
131 if(clipboardText && strlen(clipboardText) + charsUsed < 502)
132 {
133 strcpy( cons->text_entries[0].text + charsUsed, clipboardText);
134 lastPasteTime = ONgGameState->GameTime;
135 }
136 CloseClipboard();
137 }
138
139 }
140 else
141 {
142 //need to hook whatever controls however often you can repeat characters...i guess.
143 //cons->text_entries[0].text[strlen(cons->text_entries[0].text) - 1] = 0;
144 }
145 }
146 }
147}
148
149void ONICALL DDrText_Hook()
150{
151
152 if(TSrTest)
153 {
154 TSrContext_DrawText(TSrTest, "FINALLY THIS BLOODY TEXT THING WORKS\n Gotta call it at the right point...", 128, 0, &Point);
155
156 }
157
158
159 DDrPasteHack();
160
161 COrConsole_StatusLine_Display();
162
163}
Note: See TracBrowser for help on using the repository browser.