-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSteamWorks.jl
157 lines (130 loc) · 4.47 KB
/
SteamWorks.jl
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
module SteamWorks
using CEnum
export STEAM_API_DLL
STEAM_API_DLL::String = joinpath(pwd(), "steam_api64.dll")
# Replace with the actual name of the DLL file
const SteamErrMsg = NTuple{1024, Cchar}
@cenum ESteamAPIInitResult::UInt32 begin
k_ESteamAPIInitResult_OK = 0
k_ESteamAPIInitResult_FailedGeneric = 1 # Some other failure
k_ESteamAPIInitResult_NoSteamClient = 2 # We cannot connect to Steam, steam probably isn't running
k_ESteamAPIInitResult_VersionMismatch = 3 # The Steam client version is out of date
end
"""
SteamInternal_SteamAPI_Init(pOutErrMsg::Ptr{SteamErrMsg})
Initialize the Steamworks SDK.
On success, `k_ESteamAPIInitResult_OK` is returned. Otherwise, if `pOutErrMsg` is non-NULL,
it will receive a non-localized message that explains the reason for the failure.
```
"""
function SteamInternal_SteamAPI_Init(pOutErrMsg)
println(STEAM_API_DLL)
ccall((:SteamInternal_SteamAPI_Init, STEAM_API_DLL), UInt8, (Ptr{Cchar}, Ref{SteamErrMsg}), C_NULL, pOutErrMsg)
end
function SteamAPI_IsSteamRunning()
ccall((:SteamAPI_IsSteamRunning, STEAM_API_DLL), Cint, ())
end
function SteamAPI_ISteamFriends_GetPersonaName(self)
ccall((:SteamAPI_ISteamFriends_GetPersonaName, STEAM_API_DLL), Ref{NTuple{1024, Cchar}}, (Ptr{Cint},), self)
end
function SteamAPI_ISteamClient_CreateSteamPipe(self)
ccall((:SteamAPI_ISteamClient_CreateSteamPipe, STEAM_API_DLL), Cint, (Ptr{Cint},), self)
end
function SteamAPI_SteamFriends()
ccall((:SteamAPI_SteamFriends_v017, STEAM_API_DLL), Ptr{Cint}, ())
end
function SteamClient()
ccall((:SteamClient, STEAM_API_DLL), Ptr{Cint}, ())
end
function SteamAPI_SteamInput()
ccall((:SteamAPI_SteamInput_v006, STEAM_API_DLL), Ptr{Cint}, ())
end
function SteamAPI_InitEx(pOutErrMsg)
ccall((:SteamAPI_InitEx, STEAM_API_DLL), ESteamAPIInitResult, (Ptr{SteamErrMsg},), pOutErrMsg)
end
function getStringFromNTuple(msg)
characters = []
done = false
for x in msg
if x > 0 && !done
println(x)
push!(characters, Char(x))
else
done = true
continue
end
end
return join(characters)
end
function SteamAPI_RestartAppIfNecessary(appId::UInt32 = UInt32(480))
ccall((:SteamAPI_RestartAppIfNecessary, STEAM_API_DLL), Bool, (UInt32,), appId)
end
# const InputActionSetHandle_t = UInt64
# const STEAM_INPUT_HANDLE_ALL_CONTROLLERS = UInt64.m
# function SteamAPI_ISteamInput_ActivateActionSet(self, inputHandle, actionSetHandle)
# ccall((:SteamAPI_ISteamInput_ActivateActionSet, libsteamapi), Cint, (Ptr{Cint}, Cint, Cint), self, inputHandle, actionSetHandle)
# end
function CheckIfSteamIsRunning()
if SteamAPI_IsSteamRunning() == 0
println("Steam is not running")
else
println("Steam is running")
end
end
function InitSteamAPI()
errMsg = Ref{SteamErrMsg}()
initSteamAPI = SteamInternal_SteamAPI_Init(errMsg)
string_result = getStringFromNTuple(errMsg[])
if initSteamAPI == k_ESteamAPIInitResult_OK
@info ("Steam API initialized")
else
@error string_result
end
end
function InitSteamTools()
if SteamAPI_RestartAppIfNecessary()
println("Restarting app")
return
else
println("App is not restarting")
end
steamClient = SteamClient()
if steamClient == C_NULL
@error "Steam client is null"
else
@info "Steam client created"
println(unsafe_load(steamClient))
end
steamPipe = SteamAPI_ISteamClient_CreateSteamPipe(steamClient)
if steamPipe == 0
@error "Steam pipe is null"
else
@info "Steam pipe created"
println(steamPipe)
end
steamFriends = SteamAPI_SteamFriends()
if steamFriends == C_NULL
@error "Steam friends is null"
else
@info "Steam friends created"
println(unsafe_load(steamFriends))
end
personaName = SteamAPI_ISteamFriends_GetPersonaName(steamFriends)
text = getStringFromNTuple(personaName)
if personaName == C_NULL
@error "Persona name is null"
else
@info "Persona name created"
println(text)
end
steamInput = SteamAPI_SteamInput()
if steamInput == C_NULL
@error "Steam input is null"
else
@info "Steam input created"
println(unsafe_load(steamInput))
end
return (client = steamClient, pipe = steamPipe, friends = steamFriends, input = steamInput, name = text)
end
export InitSteamAPI, InitSteamTools, CheckIfSteamIsRunning
end