warcraft-3-w3ts-utils 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.lua +13 -0
- package/dist/lua_modules/w3ts/globals/index.lua +23 -0
- package/dist/lua_modules/w3ts/globals/order.lua +2 -0
- package/dist/lua_modules/w3ts/handles/camera.lua +348 -0
- package/dist/lua_modules/w3ts/handles/destructable.lua +237 -0
- package/dist/lua_modules/w3ts/handles/dialog.lua +161 -0
- package/dist/lua_modules/w3ts/handles/effect.lua +198 -0
- package/dist/lua_modules/w3ts/handles/fogmodifier.lua +76 -0
- package/dist/lua_modules/w3ts/handles/force.lua +105 -0
- package/dist/lua_modules/w3ts/handles/frame.lua +417 -0
- package/dist/lua_modules/w3ts/handles/gamecache.lua +132 -0
- package/dist/lua_modules/w3ts/handles/group.lua +215 -0
- package/dist/lua_modules/w3ts/handles/handle.lua +38 -0
- package/dist/lua_modules/w3ts/handles/image.lua +105 -0
- package/dist/lua_modules/w3ts/handles/index.lua +226 -0
- package/dist/lua_modules/w3ts/handles/item.lua +375 -0
- package/dist/lua_modules/w3ts/handles/leaderboard.lua +211 -0
- package/dist/lua_modules/w3ts/handles/multiboard.lua +193 -0
- package/dist/lua_modules/w3ts/handles/player.lua +311 -0
- package/dist/lua_modules/w3ts/handles/point.lua +80 -0
- package/dist/lua_modules/w3ts/handles/quest.lua +176 -0
- package/dist/lua_modules/w3ts/handles/rect.lua +129 -0
- package/dist/lua_modules/w3ts/handles/region.lua +72 -0
- package/dist/lua_modules/w3ts/handles/sound.lua +174 -0
- package/dist/lua_modules/w3ts/handles/texttag.lua +97 -0
- package/dist/lua_modules/w3ts/handles/timer.lua +83 -0
- package/dist/lua_modules/w3ts/handles/timerdialog.lua +86 -0
- package/dist/lua_modules/w3ts/handles/trigger.lua +265 -0
- package/dist/lua_modules/w3ts/handles/ubersplat.lua +84 -0
- package/dist/lua_modules/w3ts/handles/unit.lua +1330 -0
- package/dist/lua_modules/w3ts/handles/weathereffect.lua +42 -0
- package/dist/lua_modules/w3ts/handles/widget.lua +53 -0
- package/dist/lua_modules/w3ts/hooks/index.lua +52 -0
- package/dist/lua_modules/w3ts/index.lua +36 -0
- package/dist/lua_modules/w3ts/system/base64.lua +108 -0
- package/dist/lua_modules/w3ts/system/binaryreader.lua +74 -0
- package/dist/lua_modules/w3ts/system/binarywriter.lua +88 -0
- package/dist/lua_modules/w3ts/system/file.lua +88 -0
- package/dist/lua_modules/w3ts/system/gametime.lua +27 -0
- package/dist/lua_modules/w3ts/system/host.lua +104 -0
- package/dist/lua_modules/w3ts/system/index.lua +58 -0
- package/dist/lua_modules/w3ts/system/sync.lua +239 -0
- package/dist/lua_modules/w3ts/utils/color.lua +189 -0
- package/dist/lua_modules/w3ts/utils/index.lua +38 -0
- package/dist/lualib_bundle.lua +2733 -0
- package/dist/package.json +41 -0
- package/dist/utils/abilities.lua +107 -0
- package/dist/utils/camera.lua +46 -0
- package/dist/utils/chat-command.lua +30 -0
- package/dist/utils/color.lua +41 -0
- package/dist/utils/index.lua +125 -0
- package/dist/utils/item.lua +173 -0
- package/dist/utils/math.lua +17 -0
- package/dist/utils/minimapIcons.lua +28 -0
- package/dist/utils/misc.lua +143 -0
- package/dist/utils/physics.lua +161 -0
- package/dist/utils/players.lua +234 -0
- package/dist/utils/point.lua +60 -0
- package/dist/utils/quests.lua +47 -0
- package/dist/utils/textTag.lua +110 -0
- package/dist/utils/timer.lua +21 -0
- package/dist/utils/units.lua +102 -0
- package/package.json +4 -6
- package/dist/index.js +0 -18
- package/dist/utils/abilities.js +0 -125
- package/dist/utils/camera.js +0 -37
- package/dist/utils/chat-command.js +0 -22
- package/dist/utils/color.js +0 -141
- package/dist/utils/index.js +0 -32
- package/dist/utils/item.js +0 -124
- package/dist/utils/math.js +0 -17
- package/dist/utils/minimapIcons.js +0 -27
- package/dist/utils/misc.js +0 -175
- package/dist/utils/physics.js +0 -194
- package/dist/utils/players.js +0 -189
- package/dist/utils/point.js +0 -74
- package/dist/utils/quests.js +0 -30
- package/dist/utils/textTag.js +0 -72
- package/dist/utils/timer.js +0 -16
- package/dist/utils/units.js +0 -81
- package/tsconfig.json +0 -40
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__Class = ____lualib.__TS__Class
|
|
3
|
+
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
4
|
+
local __TS__ObjectAssign = ____lualib.__TS__ObjectAssign
|
|
5
|
+
local ____exports = {}
|
|
6
|
+
local ____handle = require("lua_modules.w3ts.handles.handle")
|
|
7
|
+
local Handle = ____handle.Handle
|
|
8
|
+
____exports.WeatherEffect = __TS__Class()
|
|
9
|
+
local WeatherEffect = ____exports.WeatherEffect
|
|
10
|
+
WeatherEffect.name = "WeatherEffect"
|
|
11
|
+
__TS__ClassExtends(WeatherEffect, Handle)
|
|
12
|
+
function WeatherEffect.prototype.____constructor(self, where, effectID)
|
|
13
|
+
if Handle:initFromHandle() then
|
|
14
|
+
Handle.prototype.____constructor(self)
|
|
15
|
+
return
|
|
16
|
+
end
|
|
17
|
+
local handle = AddWeatherEffect(where.handle, effectID)
|
|
18
|
+
if handle == nil then
|
|
19
|
+
error("w3ts failed to create unit handle.", 3)
|
|
20
|
+
end
|
|
21
|
+
Handle.prototype.____constructor(self, handle)
|
|
22
|
+
end
|
|
23
|
+
function WeatherEffect.create(self, where, effectID)
|
|
24
|
+
local handle = AddWeatherEffect(where.handle, effectID)
|
|
25
|
+
if handle then
|
|
26
|
+
local obj = self:getObject(handle)
|
|
27
|
+
local values = {}
|
|
28
|
+
values.handle = handle
|
|
29
|
+
return __TS__ObjectAssign(obj, values)
|
|
30
|
+
end
|
|
31
|
+
return nil
|
|
32
|
+
end
|
|
33
|
+
function WeatherEffect.prototype.destroy(self)
|
|
34
|
+
RemoveWeatherEffect(self.handle)
|
|
35
|
+
end
|
|
36
|
+
function WeatherEffect.prototype.enable(self, flag)
|
|
37
|
+
EnableWeatherEffect(self.handle, flag)
|
|
38
|
+
end
|
|
39
|
+
function WeatherEffect.fromHandle(self, handle)
|
|
40
|
+
return self:getObject(handle)
|
|
41
|
+
end
|
|
42
|
+
return ____exports
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__Class = ____lualib.__TS__Class
|
|
3
|
+
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
4
|
+
local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
|
|
5
|
+
local ____exports = {}
|
|
6
|
+
local ____handle = require("lua_modules.w3ts.handles.handle")
|
|
7
|
+
local Handle = ____handle.Handle
|
|
8
|
+
____exports.Widget = __TS__Class()
|
|
9
|
+
local Widget = ____exports.Widget
|
|
10
|
+
Widget.name = "Widget"
|
|
11
|
+
__TS__ClassExtends(Widget, Handle)
|
|
12
|
+
__TS__SetDescriptor(
|
|
13
|
+
Widget.prototype,
|
|
14
|
+
"life",
|
|
15
|
+
{
|
|
16
|
+
get = function(self)
|
|
17
|
+
return GetWidgetLife(self.handle)
|
|
18
|
+
end,
|
|
19
|
+
set = function(self, value)
|
|
20
|
+
SetWidgetLife(self.handle, value)
|
|
21
|
+
end
|
|
22
|
+
},
|
|
23
|
+
true
|
|
24
|
+
)
|
|
25
|
+
__TS__SetDescriptor(
|
|
26
|
+
Widget.prototype,
|
|
27
|
+
"x",
|
|
28
|
+
{get = function(self)
|
|
29
|
+
return GetWidgetX(self.handle)
|
|
30
|
+
end},
|
|
31
|
+
true
|
|
32
|
+
)
|
|
33
|
+
__TS__SetDescriptor(
|
|
34
|
+
Widget.prototype,
|
|
35
|
+
"y",
|
|
36
|
+
{get = function(self)
|
|
37
|
+
return GetWidgetY(self.handle)
|
|
38
|
+
end},
|
|
39
|
+
true
|
|
40
|
+
)
|
|
41
|
+
function Widget.fromEvent(self)
|
|
42
|
+
return self:fromHandle(GetTriggerWidget())
|
|
43
|
+
end
|
|
44
|
+
function Widget.fromHandle(self, handle)
|
|
45
|
+
local ____handle_0
|
|
46
|
+
if handle then
|
|
47
|
+
____handle_0 = self:getObject(handle)
|
|
48
|
+
else
|
|
49
|
+
____handle_0 = nil
|
|
50
|
+
end
|
|
51
|
+
return ____handle_0
|
|
52
|
+
end
|
|
53
|
+
return ____exports
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
|
|
3
|
+
local ____exports = {}
|
|
4
|
+
local oldMain = main
|
|
5
|
+
local oldConfig = config
|
|
6
|
+
local hooksMainBefore = {}
|
|
7
|
+
local hooksMainAfter = {}
|
|
8
|
+
local hooksConfigBefore = {}
|
|
9
|
+
local hooksConfigAfter = {}
|
|
10
|
+
____exports.executeHooksMainBefore = function() return __TS__ArrayForEach(
|
|
11
|
+
hooksMainBefore,
|
|
12
|
+
function(____, func) return func() end
|
|
13
|
+
) end
|
|
14
|
+
____exports.executeHooksMainAfter = function() return __TS__ArrayForEach(
|
|
15
|
+
hooksMainAfter,
|
|
16
|
+
function(____, func) return func() end
|
|
17
|
+
) end
|
|
18
|
+
function ____exports.hookedMain()
|
|
19
|
+
____exports.executeHooksMainBefore()
|
|
20
|
+
oldMain()
|
|
21
|
+
____exports.executeHooksMainAfter()
|
|
22
|
+
end
|
|
23
|
+
____exports.executeHooksConfigBefore = function() return __TS__ArrayForEach(
|
|
24
|
+
hooksConfigBefore,
|
|
25
|
+
function(____, func) return func() end
|
|
26
|
+
) end
|
|
27
|
+
____exports.executeHooksConfigAfter = function() return __TS__ArrayForEach(
|
|
28
|
+
hooksConfigAfter,
|
|
29
|
+
function(____, func) return func() end
|
|
30
|
+
) end
|
|
31
|
+
function ____exports.hookedConfig()
|
|
32
|
+
____exports.executeHooksConfigBefore()
|
|
33
|
+
oldConfig()
|
|
34
|
+
____exports.executeHooksConfigAfter()
|
|
35
|
+
end
|
|
36
|
+
main = ____exports.hookedMain
|
|
37
|
+
config = ____exports.hookedConfig
|
|
38
|
+
____exports.W3TS_HOOK = W3TS_HOOK or ({})
|
|
39
|
+
____exports.W3TS_HOOK.MAIN_BEFORE = "main::before"
|
|
40
|
+
____exports.W3TS_HOOK.MAIN_AFTER = "main::after"
|
|
41
|
+
____exports.W3TS_HOOK.CONFIG_BEFORE = "config::before"
|
|
42
|
+
____exports.W3TS_HOOK.CONFIG_AFTER = "config::after"
|
|
43
|
+
local entryPoints = {[____exports.W3TS_HOOK.MAIN_BEFORE] = hooksMainBefore, [____exports.W3TS_HOOK.MAIN_AFTER] = hooksMainAfter, [____exports.W3TS_HOOK.CONFIG_BEFORE] = hooksConfigBefore, [____exports.W3TS_HOOK.CONFIG_AFTER] = hooksConfigAfter}
|
|
44
|
+
function ____exports.addScriptHook(entryPoint, hook)
|
|
45
|
+
if not (entryPoints[entryPoint] ~= nil) then
|
|
46
|
+
return false
|
|
47
|
+
end
|
|
48
|
+
local ____entryPoints_entryPoint_0 = entryPoints[entryPoint]
|
|
49
|
+
____entryPoints_entryPoint_0[#____entryPoints_entryPoint_0 + 1] = hook
|
|
50
|
+
return true
|
|
51
|
+
end
|
|
52
|
+
return ____exports
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
local ____exports = {}
|
|
2
|
+
local tsGlobals = require("lua_modules.w3ts.globals.index")
|
|
3
|
+
do
|
|
4
|
+
local ____export = require("lua_modules.w3ts.handles.index")
|
|
5
|
+
for ____exportKey, ____exportValue in pairs(____export) do
|
|
6
|
+
if ____exportKey ~= "default" then
|
|
7
|
+
____exports[____exportKey] = ____exportValue
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
do
|
|
12
|
+
local ____export = require("lua_modules.w3ts.hooks.index")
|
|
13
|
+
for ____exportKey, ____exportValue in pairs(____export) do
|
|
14
|
+
if ____exportKey ~= "default" then
|
|
15
|
+
____exports[____exportKey] = ____exportValue
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
do
|
|
20
|
+
local ____export = require("lua_modules.w3ts.system.index")
|
|
21
|
+
for ____exportKey, ____exportValue in pairs(____export) do
|
|
22
|
+
if ____exportKey ~= "default" then
|
|
23
|
+
____exports[____exportKey] = ____exportValue
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
do
|
|
28
|
+
local ____export = require("lua_modules.w3ts.utils.index")
|
|
29
|
+
for ____exportKey, ____exportValue in pairs(____export) do
|
|
30
|
+
if ____exportKey ~= "default" then
|
|
31
|
+
____exports[____exportKey] = ____exportValue
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
____exports.tsGlobals = tsGlobals
|
|
36
|
+
return ____exports
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__StringCharAt = ____lualib.__TS__StringCharAt
|
|
3
|
+
local __TS__StringAccess = ____lualib.__TS__StringAccess
|
|
4
|
+
local __TS__StringSubstr = ____lualib.__TS__StringSubstr
|
|
5
|
+
local ____exports = {}
|
|
6
|
+
---
|
|
7
|
+
-- @noSelfInFile
|
|
8
|
+
local chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
|
9
|
+
--- Encode a string to base64.
|
|
10
|
+
--
|
|
11
|
+
-- @param input The string to encode.
|
|
12
|
+
function ____exports.base64Encode(input)
|
|
13
|
+
local output = ""
|
|
14
|
+
do
|
|
15
|
+
local block = 0
|
|
16
|
+
local charCode = 0
|
|
17
|
+
local idx = 0
|
|
18
|
+
local map = chars
|
|
19
|
+
while true do
|
|
20
|
+
local ____temp_2 = #__TS__StringCharAt(
|
|
21
|
+
input,
|
|
22
|
+
math.floor(idx) | 0
|
|
23
|
+
) > 0
|
|
24
|
+
if not ____temp_2 then
|
|
25
|
+
map = "="
|
|
26
|
+
local ____ = map
|
|
27
|
+
____temp_2 = idx % 1
|
|
28
|
+
end
|
|
29
|
+
if not ____temp_2 then
|
|
30
|
+
break
|
|
31
|
+
end
|
|
32
|
+
local ____string_byte_1 = string.byte
|
|
33
|
+
local ____input_0 = input
|
|
34
|
+
idx = idx + 3 / 4
|
|
35
|
+
charCode = ____string_byte_1(
|
|
36
|
+
____input_0,
|
|
37
|
+
math.floor(idx) + 1
|
|
38
|
+
) or 0
|
|
39
|
+
if math.floor(idx) > #input and charCode == 0 then
|
|
40
|
+
if #output % 4 == 1 then
|
|
41
|
+
return output .. "="
|
|
42
|
+
end
|
|
43
|
+
return output .. "=="
|
|
44
|
+
end
|
|
45
|
+
if charCode > 255 then
|
|
46
|
+
print("'base64Encode' failed: The string to be encoded contains characters outside of the Latin1 range.")
|
|
47
|
+
return output
|
|
48
|
+
end
|
|
49
|
+
block = block << 8 | charCode
|
|
50
|
+
output = output .. __TS__StringCharAt(
|
|
51
|
+
map,
|
|
52
|
+
math.floor(63 & block >> 8 - idx % 1 * 8)
|
|
53
|
+
)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
return output
|
|
57
|
+
end
|
|
58
|
+
--- Decode a base64 string.
|
|
59
|
+
--
|
|
60
|
+
-- @param input The base64 string to decode.
|
|
61
|
+
function ____exports.base64Decode(input)
|
|
62
|
+
local i = #input
|
|
63
|
+
do
|
|
64
|
+
while i > 0 and __TS__StringAccess(input, i) ~= "=" do
|
|
65
|
+
i = i - 1
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
local str = __TS__StringSubstr(input, 0, i - 1)
|
|
69
|
+
local output = ""
|
|
70
|
+
if #str % 4 == 1 then
|
|
71
|
+
print("'base64Decode' failed: The string to be decoded is not correctly encoded.")
|
|
72
|
+
return output
|
|
73
|
+
end
|
|
74
|
+
local bs = 0
|
|
75
|
+
do
|
|
76
|
+
local bc = 0
|
|
77
|
+
local buffer
|
|
78
|
+
local idx = 0
|
|
79
|
+
while true do
|
|
80
|
+
buffer = __TS__StringCharAt(str, idx)
|
|
81
|
+
if not buffer then
|
|
82
|
+
break
|
|
83
|
+
end
|
|
84
|
+
if #buffer == 0 then
|
|
85
|
+
break
|
|
86
|
+
end
|
|
87
|
+
buffer = (string.find(chars, buffer, nil, true) or 0) - 1
|
|
88
|
+
idx = idx + 1
|
|
89
|
+
local ____temp_5
|
|
90
|
+
local ____temp_4 = ~buffer
|
|
91
|
+
if ____temp_4 then
|
|
92
|
+
bs = bc % 4 ~= 0 and bs * 64 + buffer or buffer
|
|
93
|
+
local ____ = bs
|
|
94
|
+
local ____bc_3 = bc
|
|
95
|
+
bc = ____bc_3 + 1
|
|
96
|
+
____temp_4 = ____bc_3 % 4 ~= 0
|
|
97
|
+
end
|
|
98
|
+
if ____temp_4 then
|
|
99
|
+
output = output .. string.char(255 & bs >> (-2 * bc & 6))
|
|
100
|
+
____temp_5 = output
|
|
101
|
+
else
|
|
102
|
+
____temp_5 = 0
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
return output
|
|
107
|
+
end
|
|
108
|
+
return ____exports
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__Class = ____lualib.__TS__Class
|
|
3
|
+
local ____exports = {}
|
|
4
|
+
--- Reads primitive types from a packed binary string.
|
|
5
|
+
--
|
|
6
|
+
-- @example ```ts
|
|
7
|
+
-- // Write the values
|
|
8
|
+
-- const writer = new BinaryWriter();
|
|
9
|
+
-- writer.writeUInt8(5);
|
|
10
|
+
-- writer.writeUInt8(32);
|
|
11
|
+
-- writer.writeUInt8(78);
|
|
12
|
+
-- writer.writeUInt8(200);
|
|
13
|
+
-- writer.writeUInt32(12345678);
|
|
14
|
+
-- writer.writeString("hello");
|
|
15
|
+
-- writer.writeUInt16(45000);
|
|
16
|
+
--
|
|
17
|
+
-- // Read the values
|
|
18
|
+
-- const binaryString = writer.toString();
|
|
19
|
+
-- const reader = new BinaryReader(binaryString);
|
|
20
|
+
-- const values: any[] = [];
|
|
21
|
+
--
|
|
22
|
+
-- values[0] = reader.readUInt8(); // 5
|
|
23
|
+
-- values[1] = reader.readUInt8(); // 32
|
|
24
|
+
-- values[2] = reader.readUInt8(); // 78
|
|
25
|
+
-- values[3] = reader.readUInt8(); // 200
|
|
26
|
+
-- values[4] = reader.readUInt32(); // 12345678
|
|
27
|
+
-- values[5] = reader.readString(); // hello
|
|
28
|
+
-- values[6] = reader.readUInt16(); // 45000
|
|
29
|
+
-- ```
|
|
30
|
+
____exports.BinaryReader = __TS__Class()
|
|
31
|
+
local BinaryReader = ____exports.BinaryReader
|
|
32
|
+
BinaryReader.name = "BinaryReader"
|
|
33
|
+
function BinaryReader.prototype.____constructor(self, binaryString)
|
|
34
|
+
self.pos = 1
|
|
35
|
+
self.data = binaryString
|
|
36
|
+
end
|
|
37
|
+
function BinaryReader.prototype.read(self, fmt, size)
|
|
38
|
+
local unpacked = {string.unpack(fmt, self.data, self.pos)}
|
|
39
|
+
self.pos = self.pos + size
|
|
40
|
+
if #unpacked <= 0 then
|
|
41
|
+
return 0
|
|
42
|
+
end
|
|
43
|
+
return unpacked[1]
|
|
44
|
+
end
|
|
45
|
+
function BinaryReader.prototype.readDouble(self)
|
|
46
|
+
return self:read(">d", 4)
|
|
47
|
+
end
|
|
48
|
+
function BinaryReader.prototype.readFloat(self)
|
|
49
|
+
return self:read(">f", 4)
|
|
50
|
+
end
|
|
51
|
+
function BinaryReader.prototype.readInt16(self)
|
|
52
|
+
return self:read(">h", 2)
|
|
53
|
+
end
|
|
54
|
+
function BinaryReader.prototype.readInt32(self)
|
|
55
|
+
return self:read(">i4", 4)
|
|
56
|
+
end
|
|
57
|
+
function BinaryReader.prototype.readInt8(self)
|
|
58
|
+
return self:read(">b", 1)
|
|
59
|
+
end
|
|
60
|
+
function BinaryReader.prototype.readString(self)
|
|
61
|
+
local value = self:read(">z", 0)
|
|
62
|
+
self.pos = self.pos + (#value + 1)
|
|
63
|
+
return value
|
|
64
|
+
end
|
|
65
|
+
function BinaryReader.prototype.readUInt16(self)
|
|
66
|
+
return self:read(">H", 2)
|
|
67
|
+
end
|
|
68
|
+
function BinaryReader.prototype.readUInt32(self)
|
|
69
|
+
return self:read(">I4", 4)
|
|
70
|
+
end
|
|
71
|
+
function BinaryReader.prototype.readUInt8(self)
|
|
72
|
+
return self:read(">B", 1)
|
|
73
|
+
end
|
|
74
|
+
return ____exports
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__Class = ____lualib.__TS__Class
|
|
3
|
+
local ____exports = {}
|
|
4
|
+
--- Packs primitive types into a binary string.
|
|
5
|
+
--
|
|
6
|
+
-- @example ```ts
|
|
7
|
+
-- // Write the values
|
|
8
|
+
-- const writer = new BinaryWriter();
|
|
9
|
+
-- writer.writeUInt8(5);
|
|
10
|
+
-- writer.writeUInt8(32);
|
|
11
|
+
-- writer.writeUInt8(78);
|
|
12
|
+
-- writer.writeUInt8(200);
|
|
13
|
+
-- writer.writeUInt32(12345678);
|
|
14
|
+
-- writer.writeString("hello");
|
|
15
|
+
-- writer.writeUInt16(45000);
|
|
16
|
+
--
|
|
17
|
+
-- // Read the values
|
|
18
|
+
-- const binaryString = writer.toString();
|
|
19
|
+
-- const reader = new BinaryReader(binaryString);
|
|
20
|
+
-- const values: any[] = [];
|
|
21
|
+
--
|
|
22
|
+
-- values[0] = reader.readUInt8(); // 5
|
|
23
|
+
-- values[1] = reader.readUInt8(); // 32
|
|
24
|
+
-- values[2] = reader.readUInt8(); // 78
|
|
25
|
+
-- values[3] = reader.readUInt8(); // 200
|
|
26
|
+
-- values[4] = reader.readUInt32(); // 12345678
|
|
27
|
+
-- values[5] = reader.readString(); // hello
|
|
28
|
+
-- values[6] = reader.readUInt16(); // 45000
|
|
29
|
+
-- ```
|
|
30
|
+
____exports.BinaryWriter = __TS__Class()
|
|
31
|
+
local BinaryWriter = ____exports.BinaryWriter
|
|
32
|
+
BinaryWriter.name = "BinaryWriter"
|
|
33
|
+
function BinaryWriter.prototype.____constructor(self)
|
|
34
|
+
self.values = {}
|
|
35
|
+
self.fmj = ">"
|
|
36
|
+
end
|
|
37
|
+
function BinaryWriter.prototype.__tostring(self)
|
|
38
|
+
return string.pack(
|
|
39
|
+
self.fmj,
|
|
40
|
+
table.unpack(self.values)
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
function BinaryWriter.prototype.writeDouble(self, value)
|
|
44
|
+
self.fmj = self.fmj .. "d"
|
|
45
|
+
local ____self_values_0 = self.values
|
|
46
|
+
____self_values_0[#____self_values_0 + 1] = value
|
|
47
|
+
end
|
|
48
|
+
function BinaryWriter.prototype.writeFloat(self, value)
|
|
49
|
+
self.fmj = self.fmj .. "f"
|
|
50
|
+
local ____self_values_1 = self.values
|
|
51
|
+
____self_values_1[#____self_values_1 + 1] = value
|
|
52
|
+
end
|
|
53
|
+
function BinaryWriter.prototype.writeInt16(self, value)
|
|
54
|
+
self.fmj = self.fmj .. "h"
|
|
55
|
+
local ____self_values_2 = self.values
|
|
56
|
+
____self_values_2[#____self_values_2 + 1] = value
|
|
57
|
+
end
|
|
58
|
+
function BinaryWriter.prototype.writeInt32(self, value)
|
|
59
|
+
self.fmj = self.fmj .. "i4"
|
|
60
|
+
local ____self_values_3 = self.values
|
|
61
|
+
____self_values_3[#____self_values_3 + 1] = value
|
|
62
|
+
end
|
|
63
|
+
function BinaryWriter.prototype.writeInt8(self, value)
|
|
64
|
+
self.fmj = self.fmj .. "b"
|
|
65
|
+
local ____self_values_4 = self.values
|
|
66
|
+
____self_values_4[#____self_values_4 + 1] = value
|
|
67
|
+
end
|
|
68
|
+
function BinaryWriter.prototype.writeString(self, value)
|
|
69
|
+
self.fmj = self.fmj .. "z"
|
|
70
|
+
local ____self_values_5 = self.values
|
|
71
|
+
____self_values_5[#____self_values_5 + 1] = value
|
|
72
|
+
end
|
|
73
|
+
function BinaryWriter.prototype.writeUInt16(self, value)
|
|
74
|
+
self.fmj = self.fmj .. "H"
|
|
75
|
+
local ____self_values_6 = self.values
|
|
76
|
+
____self_values_6[#____self_values_6 + 1] = value
|
|
77
|
+
end
|
|
78
|
+
function BinaryWriter.prototype.writeUInt32(self, value)
|
|
79
|
+
self.fmj = self.fmj .. "I4"
|
|
80
|
+
local ____self_values_7 = self.values
|
|
81
|
+
____self_values_7[#____self_values_7 + 1] = value
|
|
82
|
+
end
|
|
83
|
+
function BinaryWriter.prototype.writeUInt8(self, value)
|
|
84
|
+
self.fmj = self.fmj .. "B"
|
|
85
|
+
local ____self_values_8 = self.values
|
|
86
|
+
____self_values_8[#____self_values_8 + 1] = value
|
|
87
|
+
end
|
|
88
|
+
return ____exports
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__Class = ____lualib.__TS__Class
|
|
3
|
+
local __TS__StringSubstr = ____lualib.__TS__StringSubstr
|
|
4
|
+
local ____exports = {}
|
|
5
|
+
--- A system which provides the ability to read and write files. There are no standard IO natives
|
|
6
|
+
-- so this system relies on an exploit which ended up being sanctioned by Blizzard, and because of this
|
|
7
|
+
-- there are some caveats.
|
|
8
|
+
--
|
|
9
|
+
-- - All files are confined to the `Documents\Warcraft III\CustomMapData` folder.
|
|
10
|
+
-- - The only allowed file extensions are `.txt` and `.pld`.
|
|
11
|
+
-- - Generated files contain boilerplate JASS code.
|
|
12
|
+
-- - You cannot delete files but you can empty their contents.
|
|
13
|
+
--
|
|
14
|
+
-- @example ```ts
|
|
15
|
+
-- // Write to the file
|
|
16
|
+
-- File.write("data.txt", "Hello world!");
|
|
17
|
+
--
|
|
18
|
+
-- // Read it's contents
|
|
19
|
+
-- const contents = File.read("data.txt");
|
|
20
|
+
--
|
|
21
|
+
-- // Display the contents
|
|
22
|
+
-- if (contents) {
|
|
23
|
+
-- print(contents);
|
|
24
|
+
-- }
|
|
25
|
+
-- ```
|
|
26
|
+
____exports.File = __TS__Class()
|
|
27
|
+
local File = ____exports.File
|
|
28
|
+
File.name = "File"
|
|
29
|
+
function File.prototype.____constructor(self)
|
|
30
|
+
end
|
|
31
|
+
function File.escape(self, contents)
|
|
32
|
+
contents = (string.gsub(contents, ____exports.File.escapeCharacter, ____exports.File.escapedSelf))
|
|
33
|
+
contents = (string.gsub(contents, "\"", ____exports.File.escapedQuote))
|
|
34
|
+
return contents
|
|
35
|
+
end
|
|
36
|
+
function File.unescape(self, contents)
|
|
37
|
+
contents = (string.gsub(contents, ____exports.File.escapedQuote, "\""))
|
|
38
|
+
contents = (string.gsub(contents, ____exports.File.escapedSelf, ____exports.File.escapeCharacter))
|
|
39
|
+
return contents
|
|
40
|
+
end
|
|
41
|
+
function File.read(self, filename)
|
|
42
|
+
local originalIcon = BlzGetAbilityIcon(self.dummyAbility)
|
|
43
|
+
if originalIcon == nil then
|
|
44
|
+
return nil
|
|
45
|
+
end
|
|
46
|
+
Preloader(filename)
|
|
47
|
+
local preloadText = BlzGetAbilityIcon(self.dummyAbility)
|
|
48
|
+
if preloadText == nil then
|
|
49
|
+
return nil
|
|
50
|
+
end
|
|
51
|
+
BlzSetAbilityIcon(self.dummyAbility, originalIcon)
|
|
52
|
+
if preloadText ~= originalIcon then
|
|
53
|
+
return ____exports.File:unescape(preloadText)
|
|
54
|
+
end
|
|
55
|
+
return nil
|
|
56
|
+
end
|
|
57
|
+
function File.writeRaw(self, filename, contents, allowReading)
|
|
58
|
+
if allowReading == nil then
|
|
59
|
+
allowReading = false
|
|
60
|
+
end
|
|
61
|
+
PreloadGenClear()
|
|
62
|
+
PreloadGenStart()
|
|
63
|
+
if allowReading then
|
|
64
|
+
Preload("\")\n//! beginusercode\nlocal o=''\nPreload=function(s)o=o..s end\nPreloadEnd=function()end\n//!endusercode\n//")
|
|
65
|
+
contents = ____exports.File:escape(contents)
|
|
66
|
+
end
|
|
67
|
+
do
|
|
68
|
+
local i = 0
|
|
69
|
+
while i < #contents / ____exports.File.preloadLimit do
|
|
70
|
+
Preload(__TS__StringSubstr(contents, i * ____exports.File.preloadLimit, ____exports.File.preloadLimit))
|
|
71
|
+
i = i + 1
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
if allowReading then
|
|
75
|
+
Preload(("\")\n//! beginusercode\nBlzSetAbilityIcon(" .. tostring(self.dummyAbility)) .. ",o)\n//!endusercode\n//")
|
|
76
|
+
end
|
|
77
|
+
PreloadGenEnd(filename)
|
|
78
|
+
return self
|
|
79
|
+
end
|
|
80
|
+
function File.write(self, filename, contents)
|
|
81
|
+
return self:writeRaw(filename, contents, true)
|
|
82
|
+
end
|
|
83
|
+
File.dummyAbility = FourCC("Amls")
|
|
84
|
+
File.preloadLimit = 259
|
|
85
|
+
File.escapeCharacter = string.char(27)
|
|
86
|
+
File.escapedSelf = ____exports.File.escapeCharacter .. ____exports.File.escapeCharacter
|
|
87
|
+
File.escapedQuote = ____exports.File.escapeCharacter .. "q"
|
|
88
|
+
return ____exports
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
local ____exports = {}
|
|
2
|
+
local ____timer = require("lua_modules.w3ts.handles.timer")
|
|
3
|
+
local Timer = ____timer.Timer
|
|
4
|
+
local ____index = require("lua_modules.w3ts.hooks.index")
|
|
5
|
+
local addScriptHook = ____index.addScriptHook
|
|
6
|
+
local W3TS_HOOK = ____index.W3TS_HOOK
|
|
7
|
+
local elapsedTime = 0
|
|
8
|
+
local gameTimer
|
|
9
|
+
function ____exports.getElapsedTime()
|
|
10
|
+
if not gameTimer then
|
|
11
|
+
return 0
|
|
12
|
+
end
|
|
13
|
+
return elapsedTime + gameTimer.elapsed
|
|
14
|
+
end
|
|
15
|
+
addScriptHook(
|
|
16
|
+
W3TS_HOOK.MAIN_AFTER,
|
|
17
|
+
function()
|
|
18
|
+
gameTimer = Timer:create():start(
|
|
19
|
+
30,
|
|
20
|
+
true,
|
|
21
|
+
function()
|
|
22
|
+
elapsedTime = elapsedTime + 30
|
|
23
|
+
end
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
)
|
|
27
|
+
return ____exports
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__New = ____lualib.__TS__New
|
|
3
|
+
local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
|
|
4
|
+
local ____exports = {}
|
|
5
|
+
local ____index = require("lua_modules.w3ts.handles.index")
|
|
6
|
+
local MapPlayer = ____index.MapPlayer
|
|
7
|
+
local ____timer = require("lua_modules.w3ts.handles.timer")
|
|
8
|
+
local Timer = ____timer.Timer
|
|
9
|
+
local ____index = require("lua_modules.w3ts.hooks.index")
|
|
10
|
+
local addScriptHook = ____index.addScriptHook
|
|
11
|
+
local W3TS_HOOK = ____index.W3TS_HOOK
|
|
12
|
+
local ____base64 = require("lua_modules.w3ts.system.base64")
|
|
13
|
+
local base64Decode = ____base64.base64Decode
|
|
14
|
+
local base64Encode = ____base64.base64Encode
|
|
15
|
+
local ____binaryreader = require("lua_modules.w3ts.system.binaryreader")
|
|
16
|
+
local BinaryReader = ____binaryreader.BinaryReader
|
|
17
|
+
local ____binarywriter = require("lua_modules.w3ts.system.binarywriter")
|
|
18
|
+
local BinaryWriter = ____binarywriter.BinaryWriter
|
|
19
|
+
local ____sync = require("lua_modules.w3ts.system.sync")
|
|
20
|
+
local SyncRequest = ____sync.SyncRequest
|
|
21
|
+
local lobbyTimes = {}
|
|
22
|
+
local hostCallbacks = {}
|
|
23
|
+
local localJoinTime = 0
|
|
24
|
+
local localStartTime = 0
|
|
25
|
+
local host
|
|
26
|
+
local checkTimer
|
|
27
|
+
local isChecking = false
|
|
28
|
+
function ____exports.onHostDetect(callback)
|
|
29
|
+
if host then
|
|
30
|
+
callback()
|
|
31
|
+
else
|
|
32
|
+
hostCallbacks[#hostCallbacks + 1] = callback
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
local function onConfig()
|
|
36
|
+
if localJoinTime == 0 then
|
|
37
|
+
localJoinTime = os.clock()
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
local function findHost()
|
|
41
|
+
isChecking = true
|
|
42
|
+
if localStartTime == 0 then
|
|
43
|
+
localStartTime = os.clock()
|
|
44
|
+
end
|
|
45
|
+
local writer = __TS__New(BinaryWriter)
|
|
46
|
+
writer:writeFloat(localStartTime - localJoinTime)
|
|
47
|
+
local ____self_0 = __TS__New(
|
|
48
|
+
SyncRequest,
|
|
49
|
+
MapPlayer:fromLocal(),
|
|
50
|
+
base64Encode(tostring(writer))
|
|
51
|
+
)
|
|
52
|
+
____self_0["then"](
|
|
53
|
+
____self_0,
|
|
54
|
+
function(res, req)
|
|
55
|
+
local data = base64Decode(res.data)
|
|
56
|
+
local reader = __TS__New(BinaryReader, data)
|
|
57
|
+
local syncedTime = reader:readFloat()
|
|
58
|
+
local from = MapPlayer:fromEvent()
|
|
59
|
+
lobbyTimes[from.id + 1] = syncedTime
|
|
60
|
+
local hostTime = 0
|
|
61
|
+
local hostId = 0
|
|
62
|
+
do
|
|
63
|
+
local i = 0
|
|
64
|
+
while i < bj_MAX_PLAYERS do
|
|
65
|
+
do
|
|
66
|
+
local p = MapPlayer:fromIndex(i)
|
|
67
|
+
if p == nil or p.slotState ~= PLAYER_SLOT_STATE_PLAYING or p.controller ~= MAP_CONTROL_USER then
|
|
68
|
+
goto __continue11
|
|
69
|
+
end
|
|
70
|
+
if not lobbyTimes[p.id + 1] then
|
|
71
|
+
return
|
|
72
|
+
end
|
|
73
|
+
if lobbyTimes[p.id + 1] > hostTime then
|
|
74
|
+
hostTime = lobbyTimes[p.id + 1]
|
|
75
|
+
hostId = p.id
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
::__continue11::
|
|
79
|
+
i = i + 1
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
host = MapPlayer:fromIndex(hostId)
|
|
83
|
+
if checkTimer then
|
|
84
|
+
checkTimer:destroy()
|
|
85
|
+
end
|
|
86
|
+
__TS__ArrayForEach(
|
|
87
|
+
hostCallbacks,
|
|
88
|
+
function(____, cb)
|
|
89
|
+
cb()
|
|
90
|
+
end
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
):catch(function(res)
|
|
94
|
+
print("findHost Error: " .. tostring(res.status))
|
|
95
|
+
isChecking = false
|
|
96
|
+
end)
|
|
97
|
+
end
|
|
98
|
+
local function onMain()
|
|
99
|
+
checkTimer = Timer:create()
|
|
100
|
+
checkTimer:start(0, false, findHost)
|
|
101
|
+
end
|
|
102
|
+
addScriptHook(W3TS_HOOK.MAIN_AFTER, onMain)
|
|
103
|
+
addScriptHook(W3TS_HOOK.CONFIG_BEFORE, onConfig)
|
|
104
|
+
return ____exports
|