source: Daodan/MSVC/Daodan_Utility.c@ 568

Last change on this file since 568 was 567, checked in by gumby, 14 years ago

Daodan MSVC

File size: 3.2 KB
RevLine 
[567]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 char buffer[128] = {0};
92 char* weapon_string = (char*)(*(weapon + 1)+0x5C);
93 int16_t ammo = *(int16_t *)((int)weapon + 0x56);
94 int16_t maxammo = *(int16_t *)(*(weapon + 1)+0xC0);
95 float ratio = (float)ammo / (float)maxammo;
96
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';
102
103 DDrMake_Weapon_Message( weapon_string, buffer); //gets the name of the weapon and formats it...probably doesn't need to be in seperate func.
104 sprintf(SSrMessage_Find("autoprompt_weapon"), "%s |[%c.%i/%i]|", buffer, ammocolor, ammo, maxammo); //copies the new string to ONGS
105 ONiGameState_FindAutoPromptMessage("weapon", output_ptr); //does what the code i replaced does. Basically tells the game to show the msg.
106}
107
108
109void ONICALL DDrMake_Weapon_Message(char* weapon_string, char* output_ptr) {
110 char* weapon_msg = NULL; //The normal "You have recieved X" message.
111 char weapon_name[64] = {'\0'}; //The stripped weapon name
112 //TODO, someday: dynamically detect different keybindings.
113 char default_msg[] = "Press [c.Q] to pick up weapon."; //default return
114
115 //Find the recieved message string
116 weapon_msg = SSrMessage_Find(weapon_string);
117 //this probably could be reorganized
118 if(weapon_msg) { //SSrMsgblah returns NULL if it can't find the message key
119 memcpy(weapon_name, weapon_msg, (strstr(weapon_msg," received.") - weapon_msg )); //strips uneeded characters
120 sprintf(output_ptr, "Press [c.Q] to pick up %s", weapon_name);
121 }
122 else {
123 memcpy(output_ptr, default_msg, sizeof(default_msg));
124 }
125
126}
Note: See TracBrowser for help on using the repository browser.