Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions KISSMultiplayer/lua/ge/extensions/kissconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,17 @@ local function save_config()
view_distance = kissui.view_distance[0],
base_secret_v2 = secret
}
local file = io.open("./settings/kissmp_config.json", "w")
file:write(jsonEncode(result))
io.close(file)
jsonWriteFile("/settings/kissmp_config.json", result, true)
end

local function load_config()
local file = io.open("./settings/kissmp_config.json", "r")
if not file then
if not FS:fileExists("/settings/kissmp_config.json") then
if Steam and Steam.isWorking and Steam.accountLoggedIn then
kissui.player_name = imgui.ArrayChar(32, Steam.playerName)
end
return
end
local content = file:read("*a")
local config = jsonDecode(content or "")
local config = jsonReadFile("/settings/kissmp_config.json")
if not config then return end

if config.name ~= nil then
Expand All @@ -67,7 +63,6 @@ local function load_config()
if config.base_secret_v2 ~= nil then
network.base_secret = config.base_secret_v2
end
io.close(file)
end

local function init()
Expand Down
13 changes: 3 additions & 10 deletions KISSMultiplayer/lua/ge/extensions/kissmods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ local function is_special_mod(mod_path)
return false
end

local function get_mod_name(name)
local name = string.lower(name)
name = name:gsub('.zip$', '')
return "kissmp_mods"..name
end

local function deactivate_mod(name)
local filename = "/kissmp_mods/"..name
if FS:isMounted(filename) then
Expand All @@ -31,7 +25,7 @@ local function is_app_mod(path)
if string.sub(path, -4) ~= ".zip" then
pattern = "([^/]+)$"
end

path = string.match(path, pattern)
local mod = core_modmanager.getModDB(path)
if not mod then return false end
Expand Down Expand Up @@ -62,7 +56,7 @@ local function mount_mod(name)
if FS:fileExists("/kissmp_mods/"..name) then
FS:mount("/kissmp_mods/"..name)
else
files = FS:findFiles("/mods/", name, 1000)
local files = FS:findFiles("/mods/", name, 1000)
if files[1] then
FS:mount(files[1])
else
Expand All @@ -89,7 +83,7 @@ local function update_status(mod)
for _, v in pairs(search_results2) do
table.insert(search_results, v)
end

if not search_results[1] then
mod.status = "missing"
else
Expand Down Expand Up @@ -127,7 +121,6 @@ local function open_file(name)
FS:directoryCreate("/kissmp_mods/")
end
local path = "/kissmp_mods/"..name
print(path)
local file = io.open(path, "wb")
return file
end
Expand Down
8 changes: 5 additions & 3 deletions KISSMultiplayer/lua/ge/extensions/kissmp/ui/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ local function draw_player_list()
imgui.EndGroup()
end

local message_color = imgui.ImVec4(0,0,0,0)
local function draw()
if not kissui.gui.isWindowVisible("Chat") then return end
imgui.PushStyleVar2(imgui.StyleVar_WindowMinSize, imgui.ImVec2(100, 100))
Expand Down Expand Up @@ -90,12 +91,13 @@ local function draw()
for _, message in pairs(M.chat) do
imgui.PushTextWrapPos(0)
if message.user_name ~= nil then
local color = imgui.ImVec4(message.user_color[1], message.user_color[2], message.user_color[3], message.user_color[4])
imgui.TextColored(color, "%s", (message.user_name:sub(1, 16))..":")
message_color.x, message_color.y, message_color.z, message_color.w = message.user_color[1], message.user_color[2], message.user_color[3], message.user_color[4]
imgui.TextColored(message_color, "%s", (message.user_name:sub(1, 16))..":")
imgui.SameLine()
end
if message.has_color then
imgui.TextColored(imgui.ImVec4(message.color.r or 1, message.color.g or 1, message.color.b or 1, message.color.a or 1), "%s", message.text)
message_color.x, message_color.y, message_color.z, message_color.w = message.color.r or 1, message.color.g or 1, message.color.b or 1, message.color.a or 1
imgui.TextColored(message_color, "%s", message.text)
else
imgui.Text("%s", message.text)
end
Expand Down
47 changes: 40 additions & 7 deletions KISSMultiplayer/lua/ge/extensions/kissmp/ui/download.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ local function bytes_to_mb(bytes)
return (bytes / 1024) / 1024
end

local function format_eta(seconds)
if seconds < 0 then seconds = 0 end
local hours = math.floor(seconds / 3600)
local minutes = math.floor((seconds % 3600) / 60)
local secs = math.floor(seconds % 60)

if hours > 0 then
return string.format("%02d:%02d:%02d", hours, minutes, secs)
end
return string.format("%02d:%02d", minutes, secs)
end

local function draw(gui)
if not kissui.show_download then return end

Expand Down Expand Up @@ -37,19 +49,41 @@ local function draw(gui)
imgui.ProgressBar(download_status.progress, imgui.ImVec2(split_width, 0))

local mod = kissmods.mods[download_status.name]
total_size = total_size + mod.size
downloaded_size = downloaded_size + (mod.size * download_status.progress)
local mod_size = (mod and mod.size) or 0
total_size = total_size + mod_size
downloaded_size = downloaded_size + (mod_size * download_status.progress)
end
end
imgui.EndChild()

total_size = bytes_to_mb(total_size)
downloaded_size = bytes_to_mb(downloaded_size)
local progress = downloaded_size / total_size
local total_size_bytes = network.download_total_bytes or 0
local downloaded_size_bytes = network.downloaded_bytes or 0
if total_size_bytes <= 0 then
total_size_bytes = total_size
downloaded_size_bytes = downloaded_size
end

total_size = bytes_to_mb(total_size_bytes)
downloaded_size = bytes_to_mb(downloaded_size_bytes)
local progress_text = tostring(math.floor(downloaded_size)) .. "MB / " .. tostring(math.floor(total_size)) .. "MB"

local elapsed = 0
if (network.download_start_time or 0) > 0 then
elapsed = socket.gettime() - network.download_start_time
end
if elapsed <= 0 then elapsed = 0.001 end
local progress_speed = downloaded_size / elapsed
local speed_text = tostring(math.floor(progress_speed)) .. "MB/s"

local eta_text = "--:--"
if progress_speed > 0 and downloaded_size < total_size then
local eta_seconds = (total_size - downloaded_size) / progress_speed
eta_text = format_eta(eta_seconds)
end

content_width = imgui.GetWindowContentRegionWidth()
split_width = content_width * 0.495
split_width = content_width * 0.450
progress_text = progress_text .. " (" .. speed_text .. ", ETA " .. eta_text .. ")"
local text_size = imgui.CalcTextSize(progress_text)
local extra_size = split_width - text_size.x

Expand All @@ -60,7 +94,6 @@ local function draw(gui)
end
imgui.SameLine()
if imgui.Button("Cancel###cancel_download", imgui.ImVec2(split_width, -1)) then
network.cancel_download()
kissui.show_download = false
network.disconnect()
end
Expand Down
32 changes: 19 additions & 13 deletions KISSMultiplayer/lua/ge/extensions/kissmp/ui/names.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
local M = {}

local camera_pos = vec3()
local vehicle_position = vec3()

local text_color = ColorF(1, 1, 1, 1)
local background_color = ColorI(0, 0, 0, 255)

local function draw()
camera_pos:set(core_camera.getPositionXYZ())
for id, player in pairs(network.players) do
if id ~= network.connection.client_id and player.current_vehicle then
local vehicle_id = vehiclemanager.id_map[player.current_vehicle] or -1
local vehicle = be:getObjectByID(vehicle_id)
local vehicle_position = vec3()
if (not vehicle) or (kisstransform.inactive[vehicle_id]) then
local vehicle = getObjectByID(vehicle_id)
if not vehicle or kisstransform.inactive[vehicle_id] then
if kissplayers.players[player.current_vehicle] then
vehicle_position = vec3(kissplayers.players[player.current_vehicle]:getPosition())
vehicle_position:set(kissplayers.players[player.current_vehicle]:getPositionXYZ())
elseif kisstransform.raw_transforms[player.current_vehicle] then
vehicle_position = vec3(kisstransform.raw_transforms[player.current_vehicle].position)
local position = kisstransform.raw_transforms[player.current_vehicle].position
vehicle_position:set(position[1], position[2], position[3])
end
else
vehicle_position = vec3(vehicle:getPosition())
vehicle_position:set(vehicle:getPositionXYZ())
end

local local_position = getCameraPosition()
local distance = vehicle_position:distance(vec3(local_position)) or 0

local distance = vehicle_position:distance(camera_pos) or 0
vehicle_position.z = vehicle_position.z + 1.6
debugDrawer:drawTextAdvanced(
Point3F(vehicle_position.x, vehicle_position.y, vehicle_position.z),
String(player.name.." ("..tostring(math.floor(distance)).."m)"),
ColorF(1, 1, 1, 1),
vehicle_position,
player.name.." ("..tostring(math.floor(distance)).."m)",
text_color,
true,
false,
ColorI(0, 0, 0, 255),
background_color,
false,
false
)
Expand Down
18 changes: 7 additions & 11 deletions KISSMultiplayer/lua/ge/extensions/kissmp/ui/tabs/create_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ end
local function find_map_real_path(map_path)
local patterns = {"info.json", "*.mis"}
local found_file = map_path

for _,pattern in pairs(patterns) do
local files = FS:findFiles(map_path, pattern, 1)
if #files > 0 then
found_file = files[1]
break
end
end
print(found_file)
return FS:virtual2Native(found_file)
end

Expand All @@ -74,19 +73,16 @@ local function change_map(map_info, title)

--
local map_path = map_info.misFilePath
print(map_path)
M.map = map_path
M.map_name = title or map_info.levelName

local native = find_map_real_path(map_path)
print(native)
local _, zip_end = string.find(native, ".zip")
local _, is_mod = string.find(native, "mods")
if zip_end and is_mod then
local mod_file = string.sub(native, 1, zip_end)
print(mod_file)
local virtual = to_non_lowered(FS:native2Virtual(mod_file))

pre_forced_mods_state[virtual] = (M.mods[virtual] ~= nil)
M.mods[virtual] = FS:virtual2Native(virtual)
forced_mods[virtual] = true
Expand All @@ -95,23 +91,23 @@ end

local function checkbox(id, checked, allow_click)
if allow_click == nil then allow_click = allow_click or true end

if not allow_click then imgui.PushStyleVar1(imgui.StyleVar_Alpha, 0.70) end
local return_value = imgui.Checkbox(id, checked)
if not allow_click then imgui.PopStyleVar() end

if allow_click then return return_value else return false end
end

local function draw()
imgui.Text("Server name:")
imgui.InputText("##host_server_name", M.server_name)

imgui.Text("Max players:")
if imgui.InputInt("###host_max_players", M.max_players) then
M.max_players[0] = math.max(1, math.min(255, M.max_players[0]))
end

imgui.Text("Map:")
if imgui.BeginCombo("###host_map", M.map_name) then
for k, v in pairs(core_levels.getList()) do
Expand All @@ -138,7 +134,7 @@ local function draw()
if not kissmods.is_special_mod(v) then
local forced = forced_mods[v] or false
local checked = imgui.BoolPtr(M.mods[v] ~= nil or forced)

if checkbox(v.."###host_mod"..k, checked, not forced) then
if checked[0] and not M.mods[v] then
M.mods[v] = FS:virtual2Native(v)
Expand Down
12 changes: 4 additions & 8 deletions KISSMultiplayer/lua/ge/extensions/kissmp/ui/tabs/favorites.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ local function spairs(t, order)
end

local function save_favorites()
local file = io.open("./settings/kissmp_favorites.json", "w")
file:write(jsonEncode(M.favorite_servers))
io.close(file)
jsonWriteFile("/settings/kissmp_favorites.json", M.favorite_servers, true)
end

local function load_favorites(m)
local kissui = kissui or m
local file = io.open("./settings/kissmp_favorites.json", "r")
if file then
local content = file:read("*a")
M.favorite_servers = jsonDecode(content) or {}
io.close(file)
local jsonData = jsonReadFile("/settings/kissmp_favorites.json")
if jsonData then
M.favorite_servers = jsonData
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local M = {}
local imgui = ui_imgui
local http = require("socket.http")
http.TIMEOUT = 0.5
local version = require("lua/ge/extensions/kissmp/version")
local VERSION_PRTL = version.VERSION_STR

Expand Down
Loading
Loading