forked from Bad-Scientists/AF-Script-Packet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.d
90 lines (74 loc) · 2.48 KB
/
utils.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Utils
* - miscellanous collection of useful functions
*/
func int max (var int int1, var int int2) {
if (int1 > int2) { return int1; };
return int2;
};
func int min (var int int1, var int int2) {
if (int1 > int2) { return int2; };
return int1;
};
func int abs (var int i) {
if (i < 0) { i = 0 - i; };
return i;
};
func int clamp (var int v, var int min, var int max) {
if (v < min) { return min; };
if (v > max) { return max; };
return v;
};
/*
* Credits: mud-freak
* Original post: https://forum.worldofplayers.de/forum/threads/1566398-G1-get-date-function
* Function returns current date and time in this format: YYYY-MM-DD HH:MM:SS
*/
func string GetLocalDateTimeStamp () {
//0x0075AE08 _GetLocalTime@4
const int _GetLocalTime_G1 = 7712264;
//0x007B4750 _GetLocalTime@4
const int _GetLocalTime_G2 = 8079184;
var int SystemTimePtr; SystemTimePtr = MEM_Alloc(16); // SystemTime* 0x10
CALL_PtrParam (SystemTimePtr);
CALL__stdcall (MEMINT_SwitchG1G2 (_GetLocalTime_G1, _GetLocalTime_G2));
var string timeStr; timeStr = IntToString(MEM_ReadInt(SystemTimePtr) & 2047);
timeStr = ConcatStrings(timeStr, "-");
var int mm; mm = MEM_ReadInt (SystemTimePtr+2) & 2047;
if (mm < 10) { timeStr = ConcatStrings(timeStr, "0"); };
timeStr = ConcatStrings(timeStr, IntToString(mm));
timeStr = ConcatStrings(timeStr, "-");
var int dd; dd = MEM_ReadInt(SystemTimePtr+6) & 2047;
if (dd < 10) { timeStr = ConcatStrings(timeStr, "0"); };
timeStr = ConcatStrings(timeStr, IntToString(dd));
timeStr = ConcatStrings(timeStr, " ");
var int hh; hh = MEM_ReadInt(SystemTimePtr+8) & 2047;
if (hh < 10) { timeStr = ConcatStrings(timeStr, "0"); };
timeStr = ConcatStrings(timeStr, IntToString(hh));
timeStr = ConcatStrings(timeStr, ":");
var int mi; mi = MEM_ReadInt(SystemTimePtr+10) & 2047;
if (mi < 10) { timeStr = ConcatStrings(timeStr, "0"); };
timeStr = ConcatStrings(timeStr, IntToString(mi));
timeStr = ConcatStrings(timeStr, ":");
var int ss; ss = MEM_ReadInt(SystemTimePtr+12) & 2047;
if (ss < 10) { timeStr = ConcatStrings(timeStr, "0"); };
timeStr = ConcatStrings(timeStr, IntToString(ss));
MEM_Free(SystemTimePtr);
return timeStr;
};
/*
* Returns YYYY-MM-DD
*/
func string GetLocalDate () {
var string timeStr; timeStr = GetLocalDateTimeStamp ();
timeStr = mySTR_Prefix (timeStr, 10);
return timeStr;
};
/*
* Returns MM-DD
*/
func string GetLocalDate_MMDD () {
var string timeStr; timeStr = GetLocalDateTimeStamp ();
timeStr = mySTR_SubStr (timeStr, 5, 5);
return timeStr;
};