ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/src/Daodan_Utility.c
(Generate patch)

Comparing Daodan/src/Daodan_Utility.c (file contents):
Revision 676 by gumby, Tue Nov 3 10:38:47 2009 UTC vs.
Revision 677 by alloc, Sat Mar 2 23:46:33 2013 UTC

# Line 1 | Line 1
1   #include <windows.h>
2   #include <stdlib.h>
3   #include <stdarg.h>
4 < #include <stdint.h>
4 > //#include <stdint.h>
5   #include "oni_stdio.h"
6  
7   #include "Daodan_Utility.h"
# Line 12 | Line 12 | const double fps = 60.0;
12  
13   void __cdecl DDrStartupMessage(const char* fmt, ...)
14   {
15 +
16 +        char* buffer;
17          va_list ap;
18          va_start(ap, fmt);
19 <        char* buffer = malloc(vsnprintf(NULL, 0, fmt, ap) + 1);
19 >
20 >        buffer = malloc(vsnprintf(NULL, 0, fmt, ap) + 1);
21          
22          vsprintf(buffer, fmt, ap);
23          va_end(ap);
# Line 84 | Line 87 | double ONICALL DDrMachineTime_High_Frequ
87   //      return Frequency.QuadPart;
88   }
89          
90 < void ONICALL DDrWeapon2Message(int* weapon, void* output_ptr) {
90 > void 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 <        char ammocolor = ' ';
98 <        if(ratio >= .9) ammocolor = 'g';
99 <        else if (ratio >= .5) ammocolor = 'y';
100 <        else if (ratio >= .2) ammocolor = 'o';
101 <        else ammocolor = 'r';
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 |[%s.%i/%i]|", buffer, &ammocolor, ammo, maxammo); //copies the new string to ONGS
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  
110 < void ONICALL DDrMake_Weapon_Message(char* weapon_string, char* output_ptr) {
110 > void 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.
# Line 111 | Line 118 | void ONICALL DDrMake_Weapon_Message(char
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," received.") - weapon_msg )); //strips uneeded characters
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 {
# Line 119 | Line 126 | void ONICALL DDrMake_Weapon_Message(char
126          }
127          
128   }
129 +
130 + typedef struct
131 + {
132 +        uint16_t x;
133 +        uint16_t y;
134 +
135 + } IMtPoint2D;
136 + IMtPoint2D Point = {256, 250};
137 + extern void* TSrTest;
138 + extern void* TSrScores;
139 + unsigned int lastPasteTime;
140 +
141 + //TODO: Fix what happens when you hold down paste
142 + //Check if console is open
143 + void 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 +
178 + void 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 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)