Skip to content

Commit

Permalink
SyncCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
DrNewbie committed Nov 14, 2017
1 parent 68c1baf commit c2de49a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 10 deletions.
1 change: 1 addition & 0 deletions assets/mod_overrides/AddOnThrowablesSync/Hooks/SyncAsk.lua
@@ -0,0 +1 @@
--??
22 changes: 22 additions & 0 deletions assets/mod_overrides/AddOnThrowablesSync/Hooks/SyncCheck.lua
@@ -0,0 +1,22 @@
FakeSyncFixList = FakeSyncFixList or {}
FakeSyncFixInit = FakeSyncFixInit or {}

Hooks:Add("NetworkReceivedData", "NetReceived_AddOnThrowablesSync", function(sender, sync_asked, data)
_Net = _G and _G.LuaNetworking or nil
if sync_asked and data and _Net then
if sync_asked == "AddOnFragAsk" then
data = tostring(data)
sender = tonumber(sender)
if sender >= 1 and tweak_data.blackmarket.projectiles[data] then
_Net:SendToPeer(sender, "AddOnFragReply", data)
end
elseif sync_asked == "AddOnFragReply" then
data = tostring(data)
sender = tonumber(sender)
if sender >= 1 then
FakeSyncFixList[sender] = FakeSyncFixList[sender] or {}
FakeSyncFixList[sender][data] = true
end
end
end
end)
Expand Up @@ -22,6 +22,6 @@ end

function BaseNetworkSession:send_to_peers_synched(...)
for peer_id, peer in pairs(self._peers) do
peer:send_queued_sync(FakeSyncFix(...))
peer:send_queued_sync(FakeSyncFix(peer, ...))
end
end
@@ -1,6 +1,6 @@
function ClientNetworkSession:send_to_host(...)
if self._server_peer then
self._server_peer:send(FakeSyncFix(...))
self._server_peer:send(FakeSyncFix(1, ...))
else
print("[ClientNetworkSession:send_to_host] no host")
end
Expand Down
42 changes: 34 additions & 8 deletions assets/mod_overrides/AddOnThrowablesSync/Hooks/networkpeer.lua
@@ -1,33 +1,59 @@
function FakeSyncFix(d1, d2, d3, d4, d5, ...)
FakeSyncFixList = FakeSyncFixList or {}
FakeSyncFixInit = FakeSyncFixInit or {}

function FakeSyncFix(peer, d1, d2, d3, d4, d5, ...)
local _c = function(pid, frag)
if FakeSyncFixList[pid] and FakeSyncFixList[pid][frag] then
return true
end
return false
end
local _init = function(_peer, _frage)
if _peer and _frage and not FakeSyncFixInit['ID_'.._peer:user_id()] then
FakeSyncFixInit['ID_'.._peer:user_id()] = true
_Net = _G and _G.LuaNetworking or nil
if _Net then
FakeSyncFixList[_peer:id()] = {}
_Net:SendToPeer(_peer:id(), "AddOnFragAsk", _frage)
end
end
end
local _d1 = tostring(d1)
if _d1 == 'sync_grenades' then
local projectile_tweak = tweak_data.blackmarket.projectiles[tostring(d2)]
if _d1 == 'sync_grenades' and not _c(peer:id(), d2) then
_init(peer, d2)
local projectile_tweak = tweak_data.blackmarket.projectiles[d2]
if projectile_tweak and projectile_tweak.custom then
d2 = projectile_tweak.base_on or 'concussion'
end
elseif _d1 == 'sync_unit_event_id_16' and d2 and d2.name and d2:name() then
local _d2 = tostring(d2:name():key())
if tweak_data.blackmarket.custom_projectiles[_d2] then
local _p = tweak_data.blackmarket.custom_projectiles[_d2]
if _p and not _c(peer:id(), _p) then
d2 = nil
end
elseif _d1 == 'sync_throw_projectile' then
if d2 and d2.name and d2:name() then
local _d2 = tostring(d2:name():key())
if tweak_data.blackmarket.custom_projectiles[_d2] then
local _p = tweak_data.blackmarket.custom_projectiles[_d2]
if _p and not _c(peer:id(), _p) then
d2 = nil
end
end
if d5 then
local projectile_entry = tostring(tweak_data.blackmarket:get_projectile_name_from_index(d5))
local projectile_tweak = tweak_data.blackmarket.projectiles[projectile_entry]
if projectile_tweak and projectile_tweak.custom then
if projectile_tweak and not _c(peer:id(), projectile_entry) and projectile_tweak.custom then
d5 = tweak_data.blackmarket:get_index_from_projectile_id(tweak_data.blackmarket.projectiles[projectile_entry].base_on or 'concussion')
end
end
elseif _d1 == 'request_throw_projectile' then
if type(peer) == 'number' then
peer = managers.network:session():peer(peer)
end
local projectile_entry = tostring(tweak_data.blackmarket:get_projectile_name_from_index(d2))
local projectile_tweak = tweak_data.blackmarket.projectiles[projectile_entry]
if projectile_tweak and projectile_tweak.custom then
_init(peer, projectile_entry)
if projectile_tweak and not _c(peer:id(), projectile_entry) and projectile_tweak.custom then
d2 = tweak_data.blackmarket:get_index_from_projectile_id(tweak_data.blackmarket.projectiles[projectile_entry].base_on or 'concussion')
end
end
Expand All @@ -40,6 +66,6 @@ function NetworkPeer:send_queued_sync(...)
return
end
if self._synced or self._syncing then
self:_send_queued("sync", FakeSyncFix(...))
self:_send_queued("sync", FakeSyncFix(self, ...))
end
end
2 changes: 2 additions & 0 deletions assets/mod_overrides/AddOnThrowablesSync/main.xml
Expand Up @@ -4,5 +4,7 @@
<hook file="blackmarketmanager.lua" source_file="lib/managers/blackmarketmanager"/>
<hook file="basenetworksession.lua" source_file="lib/network/base/basenetworksession"/>
<hook file="networkpeer.lua" source_file="lib/network/base/networkpeer"/>
<hook file="SyncCheck.lua" source_file="lib/managers/localizationmanager"/>
<hook file="SyncAsk.lua" source_file="lib/network/base/hostnetworksession"/>
</Hooks>
</mod>

0 comments on commit c2de49a

Please sign in to comment.