Skip to content
Open
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
86 changes: 78 additions & 8 deletions SyncAPI.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local HttpService = game:GetService('HttpService')
local RunService = game:GetService('RunService')
local InsertService = game:GetService("InsertService")
local MarketplaceService = game:GetService("MarketplaceService")

-- References
SyncAPI = script.Parent;
Expand All @@ -24,10 +26,47 @@ Options = {
CreatedInstances = {};
LastParents = {};

-- Provide cached data for requests
local assetTypeCache = {}
local imageIdCache = {}
local IsHttpServiceEnabled = nil

-- Determine whether we're in tool or plugin mode
ToolMode = (Tool.Parent:IsA 'Plugin') and 'Plugin' or 'Tool'

local IsHttpServiceEnabled = nil
-- Get asset type from asset id
local function getAssetType(assetId)
if assetTypeCache[assetId] then
return assetTypeCache[assetId]
end

local success, result = pcall(MarketplaceService.GetProductInfo, MarketplaceService, assetId, Enum.InfoType.Asset)

if success and result and result.AssetTypeId then
assetTypeCache[assetId] = result.AssetTypeId
return result.AssetTypeId
else
return nil
end
end

-- Extract imageid from decalid via insertservice
local function getImageFromDecal(assetId)
if imageIdCache[assetId] then
return imageIdCache[assetId]
end

local success, result = pcall(function()
return string.match(InsertService:LoadAsset(assetId):FindFirstChildWhichIsA("Decal").Texture, "^.-(%d+)/?$")
end)

if success and result then
imageIdCache[assetId] = result
return success and result
else
return nil
end
end

-- List of actions that could be requested
Actions = {
Expand Down Expand Up @@ -1587,7 +1626,7 @@ Actions = {
-- Push serialized data to server
local Response = HttpService:JSONDecode(
HttpService:PostAsync(
'http://f3xteam.com/bt/export',
'https://f3xteam.com/bt/export',
HttpService:JSONEncode { data = SerializedBuildData, version = 3, userId = (Player and Player.UserId) },
Enum.HttpContentType.ApplicationJson,
true
Expand Down Expand Up @@ -1618,7 +1657,7 @@ Actions = {

-- Perform test HTTP request
local DidSucceed, Result = pcall(function ()
return HttpService:GetAsync('https://google.com')
return HttpService:GetAsync('https://www.google.com/robots.txt')
end)

-- Determine whether HttpService is enabled based on whether request succeeded
Expand All @@ -1634,31 +1673,62 @@ Actions = {
['ExtractMeshFromAsset'] = function (AssetId)
-- Returns the first found mesh in the given asset

-- Ensure valid asset ID is given
assert(type(AssetId) == 'number', 'Invalid asset ID');

-- Add automatic checking for image assets which works client-sided for better UX
if getAssetType(AssetId) == 1 then
return string.format([[{"success":true,"textureID":%d}]], AssetId)
end

-- Offload action to server-side if API is running locally
if RunService:IsClient() and not RunService:IsStudio() then
return SyncAPI.ServerEndpoint:InvokeServer('ExtractMeshFromAsset', AssetId);
end;

-- Ensure valid asset ID is given
assert(type(AssetId) == 'number', 'Invalid asset ID');
-- Add support for decals which can be inserted via InsertService
if getAssetType(AssetId) == 13 then
local imageId = getImageFromDecal(AssetId)

if imageId then
return string.format([[{"success":true,"textureID":%d}]], imageId)
end
end

-- Return parsed response from API
return HttpService:JSONDecode(
HttpService:GetAsync('http://f3xteam.com/bt/getFirstMeshData/' .. AssetId)
HttpService:GetAsync('https://f3xteam.com/bt/getFirstMeshData/' .. AssetId)
);

end;

['ExtractImageFromDecal'] = function (DecalAssetId)
-- Returns the first image found in the given decal asset

-- Ensure valid asset ID is given
assert(type(DecalAssetId) == 'number', 'Invalid asset ID');

-- Add automatic checking for image assets which works client-sided for better UX
if getAssetType(DecalAssetId) == 1 then
return DecalAssetId
end

-- Offload action to server-side if API is running locally
if RunService:IsClient() and not RunService:IsStudio() then
return SyncAPI.ServerEndpoint:InvokeServer('ExtractImageFromDecal', DecalAssetId);
end;

-- Add support for decals which can be inserted via InsertService
if getAssetType(DecalAssetId) == 13 then
local imageId = getImageFromDecal(DecalAssetId)

if imageId then
return imageId
end
end

-- Return direct response from the API
return HttpService:GetAsync('http://f3xteam.com/bt/getDecalImageID/' .. DecalAssetId);
return HttpService:GetAsync('https://f3xteam.com/bt/getDecalImageID/' .. DecalAssetId);

end;

Expand Down Expand Up @@ -1955,4 +2025,4 @@ return {

end;

};
};