ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/MSVC/Daodan_Utility.c
Revision: 572
Committed: Sun Aug 29 19:13:47 2010 UTC (15 years, 1 month ago) by gumby
Content type: text/x-csrc
File size: 3617 byte(s)
Log Message:
Stuff

File Contents

# Content
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
11 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
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 /*
37 int64_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
56 int64_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
69 int64_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
80 double 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
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
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
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.
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," received.") - weapon_msg )); //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 typedef struct
130 {
131 uint16_t x;
132 uint16_t y;
133
134 } IMtPoint2D;
135 IMtPoint2D Point = {256, 250};
136 extern void* TSrTest;
137 void ONICALL DDrText_Hook()
138 {
139 if(TSrTest)
140 {
141 TSrContext_DrawText(TSrTest, "FINALLY THIS BLOODY TEXT THING WORKS\n Gotta call it at the right point...", 128, 0, &Point);
142 }
143 COrConsole_StatusLine_Display();
144
145 }