Compare commits

..

29 Commits

Author SHA1 Message Date
Jeft
1b2324deeb stop macro from returning 2023-09-14 16:15:39 -05:00
Jeft
742f7b4ec0 we Love errors 2023-09-13 09:13:23 -05:00
2cb346f49a re-prompt action 2023-09-13 00:28:59 -07:00
e5cca9ed04 common location 2023-09-12 19:29:51 -07:00
52d911a25a implement Exit/Delete 2023-09-12 19:29:51 -07:00
7ab20f36a7 fix parse 2023-09-12 19:05:01 -07:00
a7554da1c5 flush prompt 2023-09-12 19:05:01 -07:00
37f0dad7a1 ref cannot refer to object in another dom 2023-09-12 19:05:01 -07:00
e309f15cb8 implement extract 2023-09-12 19:04:46 -07:00
29374e4ff5 write edited file and report how many scripts were replaced 2023-09-12 19:04:46 -07:00
b7d04d1f40 this is wrong 2023-09-12 18:17:04 -07:00
432ec11ea6 fix write_dom 2023-09-12 18:17:04 -07:00
01449b1850 fix int parsing 2023-09-12 18:17:04 -07:00
327d0a4992 print map script stats on completion 2023-09-12 18:17:04 -07:00
420dbaa022 implement blocked in interactive 2023-09-12 18:17:04 -07:00
cad29af4bb panic lol 2023-09-12 18:17:04 -07:00
e0e8744bfd interactive mode v1 2023-09-12 18:17:04 -07:00
b434dce0f6 helper funcs 2023-09-12 18:17:04 -07:00
6ef8fd2f69 get_full_name 2023-09-12 18:17:04 -07:00
7234065bd8 fail better 2023-09-12 18:17:04 -07:00
41d8e700c5 Commands::Interactive 2023-09-12 18:17:04 -07:00
4ca3d56f0f upload comments 2023-09-12 18:17:04 -07:00
593b6902fd Scan::Flagged 2023-09-12 18:17:04 -07:00
7523c4313a scan enum, Source property missing if fatal 2023-09-12 18:17:04 -07:00
694440bd29 use wget to download maps 2023-09-12 18:17:04 -07:00
755e1d4d5b optimize release binary size 2023-09-12 18:17:04 -07:00
4334a6f330 v2 with clap 2023-09-12 18:17:04 -07:00
553ad2cca5 add clap dep 2023-09-12 18:17:03 -07:00
3f15d2f5a8 delete recursive function 2023-09-12 18:16:45 -07:00
10 changed files with 730 additions and 13469 deletions

179
Cargo.lock generated
View File

@ -2,6 +2,54 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "anstream"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46"
[[package]]
name = "anstyle-parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]] [[package]]
name = "arrayref" name = "arrayref"
version = "0.3.7" version = "0.3.7"
@ -76,6 +124,52 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a13b88d2c62ff462f88e4a121f17a82c1af05693a2f192b5c38d14de73c19f6"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961"
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
version = "0.3.0" version = "0.3.0"
@ -124,6 +218,12 @@ dependencies = [
"wasi", "wasi",
] ]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@ -166,6 +266,7 @@ dependencies = [
name = "map-tool" name = "map-tool"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap",
"rbx_binary", "rbx_binary",
"rbx_dom_weak", "rbx_dom_weak",
"rbx_reflection_database", "rbx_reflection_database",
@ -364,6 +465,12 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "subtle" name = "subtle"
version = "2.5.0" version = "2.5.0"
@ -413,6 +520,12 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"
@ -424,3 +537,69 @@ name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"

View File

@ -6,6 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
clap = { version = "4.4.2", features = ["derive"] }
rbx_binary = "0.7.1" rbx_binary = "0.7.1"
rbx_dom_weak = "2.5.0" rbx_dom_weak = "2.5.0"
rbx_reflection_database = "0.2.7" rbx_reflection_database = "0.2.7"
[profile.release]
lto = true
strip = true
codegen-units = 1

Binary file not shown.

View File

@ -1,126 +0,0 @@
--local Model=game:GetService'InsertService':LoadAsset(1079831188):GetChildren()[1] Model:SetModelCFrame(CFrame.new(0,Model:GetModelSize().y/2,0))
--[[ Load ID list
local ids={5692157375}
local ServerStorage=game:GetService'ServerStorage'
local function load(id)
local Model=game:GetObjects("rbxassetid://"..id)[1]
Model.Parent=workspace
Model:MoveTo(Vector3.new(0,Model:GetExtentsSize().y/2,0))
wait()
Model.Parent=ServerStorage
end
for i=1,#ids do
local succ,err=ypcall(load,ids[i])
if not succ then
print(ids[i],"error",err)
end
end
--]]
--[[ Format map names
local c=game:GetService'ServerStorage':GetChildren()
for i=1,#c do
local le_name=c[i].Name:gsub("%s+","_"):lower()
c[i].Name=le_name
local DisplayName=c[i]:FindFirstChild("DisplayName",true)
if DisplayName and DisplayName.ClassName=="StringValue" then
local dn=DisplayName.Value
local ndn={}
for w in dn:gmatch'%S+' do
ndn[#ndn+1]=w:sub(1,1):upper()..w:sub(2)
end
if table.concat(ndn," ")~=dn then
print("Fix name:",le_name)
end
end
end
--]]
--[[ Duplicate script labeler
local IsA=game.IsA
local ID=0
local SourceHash={}
local SourceHashCount={}
local NameHash={}
local IDHash={}
local c=game:GetService'ServerStorage':GetDescendants()
for i=1,#c do
local s=c[i]
if IsA(s,"LuaSourceContainer") then
local src=s.Source
NameHash[s]=s.Name
local id=SourceHash[src]
if id then
s.Name="copy "..id
SourceHashCount[id]=SourceHashCount[id]+1
else
ID=ID+1
IDHash[ID]=s
SourceHash[src]=ID
SourceHashCount[ID]=1
if src:find'getfenv' or src:find'require' then
s.Name="flagged "..ID
else
s.Name="unique "..ID
end
end
end
end
for i=1,ID do
local s=IDHash[i]
local hc=SourceHashCount[i]
s.Name=s.Name..(hc==1 and " (1 copy)" or " ("..hc.." copies)")
end
_G.NameHash=NameHash
--]]
--[[ Undo labeler
local NameHash=_G.NameHash
for s,n in next,NameHash do
s.Name=n
end
--]]
local IsA=workspace.IsA
local GetChildren=workspace.GetChildren
local function rsearch(search,cond1,cond2)
local found={}
for _,thing in next,GetChildren(search) do
if not cond1 or cond1(thing) then
found[#found+1]=thing
end
if not cond2 or cond2(thing) then
local nfound=#found
local r=rsearch(thing,cond1,cond2)
for i=1,#r do
found[nfound+i]=r[i]
end
end
end
return found
end
local function cond1(thing)
return IsA(thing,"LuaSourceContainer")
end
local Maps=GetChildren(game:GetService'ServerStorage')
for i=1,#Maps do
local Map=Maps[i]
if Map.ClassName=="Model" then
local Scripts=rsearch(Map,cond1)
if #Scripts>0 then
local ScriptHolder=Instance.new("Model",workspace)
ScriptHolder.Name=Map.Name.."("..#Scripts..")"
for i=1,#Scripts do
local sc=Scripts[i]
local scd
if sc.ClassName~="ModuleScript" then
sc.Disabled=true
end
local s=sc:Clone()
s.Name=sc:GetFullName()
s.Parent=ScriptHolder
if sc.ClassName~="ModuleScript" then
sc.Disabled=scd
end
end
end
end
end

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,126 +0,0 @@
--local Model=game:GetService'InsertService':LoadAsset(1079831188):GetChildren()[1] Model:SetModelCFrame(CFrame.new(0,Model:GetModelSize().y/2,0))
--[[ Load ID list
local ids={5692157375}
local ServerStorage=game:GetService'ServerStorage'
local function load(id)
local Model=game:GetObjects("rbxassetid://"..id)[1]
Model.Parent=workspace
Model:MoveTo(Vector3.new(0,Model:GetExtentsSize().y/2,0))
wait()
Model.Parent=ServerStorage
end
for i=1,#ids do
local succ,err=ypcall(load,ids[i])
if not succ then
print(ids[i],"error",err)
end
end
--]]
--[[ Format map names
local c=game:GetService'ServerStorage':GetChildren()
for i=1,#c do
local le_name=c[i].Name:gsub("%s+","_"):lower()
c[i].Name=le_name
local DisplayName=c[i]:FindFirstChild("DisplayName",true)
if DisplayName and DisplayName.ClassName=="StringValue" then
local dn=DisplayName.Value
local ndn={}
for w in dn:gmatch'%S+' do
ndn[#ndn+1]=w:sub(1,1):upper()..w:sub(2)
end
if table.concat(ndn," ")~=dn then
print("Fix name:",le_name)
end
end
end
--]]
--[[ Duplicate script labeler
local IsA=game.IsA
local ID=0
local SourceHash={}
local SourceHashCount={}
local NameHash={}
local IDHash={}
local c=game:GetService'ServerStorage':GetDescendants()
for i=1,#c do
local s=c[i]
if IsA(s,"LuaSourceContainer") then
local src=s.Source
NameHash[s]=s.Name
local id=SourceHash[src]
if id then
s.Name="copy "..id
SourceHashCount[id]=SourceHashCount[id]+1
else
ID=ID+1
IDHash[ID]=s
SourceHash[src]=ID
SourceHashCount[ID]=1
if src:find'getfenv' or src:find'require' then
s.Name="flagged "..ID
else
s.Name="unique "..ID
end
end
end
end
for i=1,ID do
local s=IDHash[i]
local hc=SourceHashCount[i]
s.Name=s.Name..(hc==1 and " (1 copy)" or " ("..hc.." copies)")
end
_G.NameHash=NameHash
--]]
--[[ Undo labeler
local NameHash=_G.NameHash
for s,n in next,NameHash do
s.Name=n
end
--]]
local IsA=workspace.IsA
local GetChildren=workspace.GetChildren
local function rsearch(search,cond1,cond2)
local found={}
for _,thing in next,GetChildren(search) do
if not cond1 or cond1(thing) then
found[#found+1]=thing
end
if not cond2 or cond2(thing) then
local nfound=#found
local r=rsearch(thing,cond1,cond2)
for i=1,#r do
found[nfound+i]=r[i]
end
end
end
return found
end
local function cond1(thing)
return IsA(thing,"LuaSourceContainer")
end
local Maps=GetChildren(game:GetService'ServerStorage')
for i=1,#Maps do
local Map=Maps[i]
if Map.ClassName=="Model" then
local Scripts=rsearch(Map,cond1)
if #Scripts>0 then
local ScriptHolder=Instance.new("Model",workspace)
ScriptHolder.Name=Map.Name.."("..#Scripts..")"
for i=1,#Scripts do
local sc=Scripts[i]
local scd
if sc.ClassName~="ModuleScript" then
sc.Disabled=true
end
local s=sc:Clone()
s.Name=sc:GetFullName()
s.Parent=ScriptHolder
if sc.ClassName~="ModuleScript" then
sc.Disabled=scd
end
end
end
end
end

21
src/error.rs Normal file
View File

@ -0,0 +1,21 @@
#[derive(Debug)]
pub struct Error {
pub message: String,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}
impl std::error::Error for Error {}
impl Error {
// has to be Box<Self> to fit with the result in prelude.rs
pub fn new(message: &str) -> Box<Self> {
Box::new(Self {
message: message.to_string(),
})
}
}

View File

@ -1,3 +1,43 @@
use std::unimplemented;
use clap::{Args, Parser, Subcommand};
mod error;
mod prelude;
// this * means we are importing everything from the prelude module and in turn we overwrite the default `Result` with our own
// if you want the original back you can use StdResult<T, E> or just std::result::Result<T, E>
// using the new result also means the error type is implicitly Box<dyn std::error::Error> (works for any errors that implement the std::error::Error trait)
use crate::prelude::*;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Download(MapList),
Upload,
Scan,
Extract(Map),
Replace,
Interactive,
}
#[derive(Args)]
struct Map {
id:u64,
}
#[derive(Args)]
struct MapList {
maps: Vec<u64>,
}
fn class_is_a(class: &str, superclass: &str) -> bool { fn class_is_a(class: &str, superclass: &str) -> bool {
if class==superclass { if class==superclass {
return true return true
@ -10,7 +50,6 @@ fn class_is_a(class: &str, superclass: &str) -> bool {
} }
return false return false
} }
fn recursive_collect_scripts(scripts: &mut std::vec::Vec<rbx_dom_weak::types::Ref>,dom: &rbx_dom_weak::WeakDom, instance: &rbx_dom_weak::Instance){ fn recursive_collect_scripts(scripts: &mut std::vec::Vec<rbx_dom_weak::types::Ref>,dom: &rbx_dom_weak::WeakDom, instance: &rbx_dom_weak::Instance){
for &referent in instance.children() { for &referent in instance.children() {
if let Some(c) = dom.get_by_ref(referent) { if let Some(c) = dom.get_by_ref(referent) {
@ -21,53 +60,482 @@ fn recursive_collect_scripts(scripts: &mut std::vec::Vec<rbx_dom_weak::types::Re
} }
} }
} }
fn get_full_name(dom:&rbx_dom_weak::WeakDom,instance:&rbx_dom_weak::Instance) -> String{
let mut full_name=instance.name.clone();
let mut pref=instance.parent();
while let Some(parent)=dom.get_by_ref(pref){
full_name.insert(0, '.');
full_name.insert_str(0, &parent.name);
pref=parent.parent();
}
full_name
}
fn main() -> Result<(), Box<dyn std::error::Error>> { //download
// Using buffered I/O is recommended with rbx_binary //download list of maps to maps/unprocessed
let input = std::io::BufReader::new(std::fs::File::open("map.rbxm")?); //scan (scripts)
//iter maps/unprocessed
//passing moves to maps/verified
//failing moves to maps/blocked
//replace (edits & deletions)
//iter maps/blocked
//replace scripts and put in maps/unprocessed
//upload
//iter maps/verified
//interactively print DisplayName/Creator and ask for target upload ids
//interactive
//iter maps/unprocessed
//for each unique script, load it into the file current.lua and have it open in sublime text
//I can edit the file and it will edit it in place
//I pass/fail(with comment)/allow each script
fn get_script_refs(dom:&rbx_dom_weak::WeakDom) -> Vec<rbx_dom_weak::types::Ref>{
let mut scripts = std::vec::Vec::new();
recursive_collect_scripts(&mut scripts, dom, dom.root());
scripts
}
fn get_id() -> Result<u32>{
match std::fs::read_to_string("id"){
Ok(id_file)=>Ok(id_file.parse::<u32>()?),
Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => Ok(0),//implicitly take on id=0
_ => Err(e)?,
}
}
}
fn get_set_from_file(file:&str) -> Result<std::collections::HashSet<String>>{
let mut set=std::collections::HashSet::<String>::new();
for entry in std::fs::read_dir(file)? {
set.insert(std::fs::read_to_string(entry?.path())?);
}
Ok(set)
}
fn get_allowed_set() -> Result<std::collections::HashSet<String>>{
get_set_from_file("scripts/allowed")
}
fn get_blocked() -> Result<std::collections::HashSet<String>>{
get_set_from_file("scripts/blocked")
}
fn get_allowed_map() -> Result<std::collections::HashMap::<u32,String>>{
let mut allowed_map = std::collections::HashMap::<u32,String>::new();
for entry in std::fs::read_dir("scripts/allowed")? {
let entry=entry?;
allowed_map.insert(entry.path().file_stem().unwrap().to_str().unwrap().parse::<u32>()?,std::fs::read_to_string(entry.path())?);
}
Ok(allowed_map)
}
fn get_replace_map() -> Result<std::collections::HashMap::<String,u32>>{
let mut replace = std::collections::HashMap::<String,u32>::new();
for entry in std::fs::read_dir("scripts/replace")? {
let entry=entry?;
replace.insert(std::fs::read_to_string(entry.path())?,entry.path().file_stem().unwrap().to_str().unwrap().parse::<u32>()?);
}
Ok(replace)
}
fn check_source_illegal_keywords(source:&String)->bool{
source.find("getfenv").is_some()||source.find("require").is_some()
}
fn download(map_list: Vec<u64>) -> Result<()>{
let header=format!("Cookie: .ROBLOSECURITY={}",std::env::var("RBXCOOKIE")?);
let shared_args=&[
"-q",
"--header",
header.as_str(),
"-O",
];
for map_id in map_list.iter() {
std::process::Command::new("wget")
.args(shared_args)
.arg(format!("maps/unprocessed/{}.rbxl",map_id))
.arg(format!("https://assetdelivery.roblox.com/v1/asset/?ID={}",map_id))
.spawn()?;
}
Ok(())
}
enum Scan{
Passed,
Blocked,
Flagged,
}
fn scan() -> Result<()>{
let mut id = get_id()?;
//Construct allowed scripts
let allowed_set = get_allowed_set()?;
let mut blocked = get_blocked()?;
for entry in std::fs::read_dir("maps/unprocessed")? {
let file_thing=entry?;
let input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
let dom = rbx_binary::from_reader(input)?; let dom = rbx_binary::from_reader(input)?;
//Construct allowed scripts let script_refs = get_script_refs(&dom);
let mut allowed = std::collections::HashSet::<String>::new();
for entry in std::fs::read_dir("allowed")? {
allowed.insert(std::fs::read_to_string(entry?.path())?);
}
let mut scripts = std::vec::Vec::<rbx_dom_weak::types::Ref>::new(); //check scribb
recursive_collect_scripts(&mut scripts, &dom, dom.root()); let mut fail_count=0;
let mut fail_type=Scan::Passed;
for &script_ref in script_refs.iter() {
if let Some(script)=dom.get_by_ref(script_ref){
if let Some(rbx_dom_weak::types::Variant::String(s)) = script.properties.get("Source") {
//flag keywords and instantly fail
if check_source_illegal_keywords(s){
println!("{:?} - flagged.",file_thing.file_name());
fail_type=Scan::Flagged;
break;
}
if allowed_set.contains(s) {
continue;
}else{
fail_type=Scan::Blocked;//no need to check for Flagged, it breaks the loop.
fail_count+=1;
if !blocked.contains(s) {
blocked.insert(s.clone());//all fixed! just clone!
std::fs::write(format!("scripts/blocked/{}.lua",id),s)?;
id+=1;
}
}
}else{
panic!("FATAL: failed to get source for {:?}",file_thing.file_name());
}
}else{
panic!("FATAL: failed to get_by_ref {:?}",script_ref);
}
}
let mut dest=match fail_type {
Scan::Passed => std::path::PathBuf::from("maps/processed"),
Scan::Blocked => {
println!("{:?} - {} {} not allowed.",file_thing.file_name(),fail_count,if fail_count==1 {"script"}else{"scripts"});
std::path::PathBuf::from("maps/blocked")
}
Scan::Flagged => std::path::PathBuf::from("maps/flagged")
};
dest.push(file_thing.file_name());
std::fs::rename(file_thing.path(), dest)?;
}
std::fs::write("id",id.to_string())?;
Ok(())
}
fn extract(file_id:u64) -> Result<()>{
let mut id = 0;
//Construct allowed scripts
let mut script_set = std::collections::HashSet::<String>::new();
let file_id_string=file_id.to_string();
for entry in std::fs::read_dir("maps/unprocessed")? {
let file_thing=entry?;
if file_thing.file_name().to_str().unwrap().find(&file_id_string).is_none(){
continue;
}
let input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
let dom = rbx_binary::from_reader(input)?;
let script_refs = get_script_refs(&dom);
//extract scribb
for &script_ref in script_refs.iter() {
if let Some(script)=dom.get_by_ref(script_ref){
if let Some(rbx_dom_weak::types::Variant::String(s)) = script.properties.get("Source") {
if script_set.contains(s) {
continue;
}else{
script_set.insert(s.clone());
std::fs::write(format!("scripts/extracted/{:?}_{}_{}.lua",file_thing.file_name(),id,script.name),s)?;
id+=1;
}
}else{
panic!("FATAL: failed to get source for {:?}",file_thing.file_name());
}
}else{
panic!("FATAL: failed to get_by_ref {:?}",script_ref);
}
}
}
println!("extracted {} {}",id,if id==1 {"script"}else{"scripts"});
Ok(())
}
fn replace() -> Result<()>{
let allowed_map=get_allowed_map()?;
let replace_map=get_replace_map()?;
for entry in std::fs::read_dir("maps/blocked")? {
let file_thing=entry?;
let input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
let mut dom = rbx_binary::from_reader(input)?;
let script_refs = get_script_refs(&dom);
//check scribb //check scribb
let mut any_failed=false; let mut any_failed=false;
for (i,&referent) in scripts.iter().enumerate() { for &script_ref in script_refs.iter() {
if let Some(script) = dom.get_by_ref(referent) { if let Some(script)=dom.get_by_ref(script_ref){
if let Some(rbx_dom_weak::types::Variant::String(s)) = script.properties.get("Source") { if let Some(rbx_dom_weak::types::Variant::String(source)) = script.properties.get("Source") {
if allowed.contains(s) { if let (Some(replace_id),Some(replace_script))=(replace_map.get(source),dom.get_by_ref_mut(script.referent())) {
println!("pass"); println!("replace {}",replace_id);
//replace the source
if let Some(replace_source)=allowed_map.get(replace_id){
replace_script.properties.insert("Source".to_string(), rbx_dom_weak::types::Variant::String(replace_source.clone()));
}else{ }else{
println!("fail"); println!("failed to get replacement source {}",replace_id);
any_failed=true;
std::fs::write(format!("blocked/{}.lua",i),s)?;
}
}else{
println!("failed to get source");
any_failed=true; any_failed=true;
} }
}else{ }else{
println!("failed to deref script"); println!("failed to failed to get replace_id and replace_script");
any_failed=true; any_failed=true;
} }
}else{
panic!("FATAL: failed to get source for {:?}",file_thing.file_name());
}
}else{
panic!("FATAL: failed to get_by_ref {:?}",script_ref);
}
} }
if any_failed { if any_failed {
println!("One or more scripts are not allowed."); println!("One or more scripts failed to replace.");
return Ok(())//everything is not ok but idk how to return an error LMAO }else{
let mut dest=std::path::PathBuf::from("maps/unprocessed");
dest.set_file_name(file_thing.file_name());
let output = std::io::BufWriter::new(std::fs::File::open(dest)?);
rbx_binary::to_writer(output, &dom, &[dom.root_ref()])?;
} }
println!("All scripts passed!"); }
Ok(())
}
fn upload() -> Result<()>{
//interactive prompt per upload:
//Creator: [auto fill creator]
//DisplayName: [auto fill DisplayName]
//id: ["New" for blank because of my double enter key]
// std::process::Command::new("rbxcompiler") // std::process::Command::new("rbxcompiler")
// .arg("--compile=false") // .arg("--compile=false")
// .arg("--group=6980477") // .arg("--group=6980477")
// .arg("--asset=5692139100") // .arg("--asset=5692139100")
// .arg("--input=map.rbxm") // .arg("--input=map.rbxm")
// .spawn()?; // .spawn()?;
unimplemented!()
}
enum Interactive{
Passed,
Blocked,
Flagged,
}
enum ScriptAction {
Pass,
Replace(u32),
Flag,
Block,
Delete,
}
enum ScriptActionParseResult {
Pass,
Block,
Exit,
Delete,
}
struct ParseScriptActionErr;
impl std::str::FromStr for ScriptActionParseResult {
type Err=ParseScriptActionErr;
fn from_str(s: &str) -> StdResult<Self, Self::Err>{
if s=="pass\n"||s=="1\n"{
Ok(Self::Pass)
}else if s=="block\n"{
Ok(Self::Block)
}else if s=="exit\n"{
Ok(Self::Exit)
}else if s=="delete\n"{
Ok(Self::Delete)
}else{
Err(ParseScriptActionErr)
}
}
}
fn interactive() -> Result<()>{
let mut id=get_id()?;
//Construct allowed scripts
let mut allowed_set=get_allowed_set()?;
let mut allowed_map=get_allowed_map()?;
let mut replace_map=get_replace_map()?;
let mut blocked = get_blocked()?;
'map_loop: for entry in std::fs::read_dir("maps/unprocessed")? {
let file_thing=entry?;
println!("processing map={:?}",file_thing.file_name());
let input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
let mut dom = rbx_binary::from_reader(input)?;
let script_refs = get_script_refs(&dom);
//check scribb
let mut script_count=0;
let mut replace_count=0;
let mut block_count=0;
let mut fail_type=Interactive::Passed;
for &script_ref in script_refs.iter() {
if let Some(script)=dom.get_by_ref(script_ref){
if let Some(rbx_dom_weak::types::Variant::String(source)) = script.properties.get("Source") {
script_count+=1;
let source_action=if check_source_illegal_keywords(source) {
ScriptAction::Flag//script triggers flagging -> Flag
} else if blocked.contains(source) {
ScriptAction::Block//script is blocked -> Block
} else if allowed_set.contains(source) {
ScriptAction::Pass//script is allowed -> Pass
}else if let Some(replace_id)=replace_map.get(source) {
ScriptAction::Replace(*replace_id)
}else{
//interactive logic goes here
print!("unresolved source location={}\naction: ",get_full_name(&dom, script));
std::io::Write::flush(&mut std::io::stdout())?;
//load source into current.lua
std::fs::write("current.lua",source)?;
//prompt action in terminal
//wait for input
let script_action;
loop{
let mut action_string = String::new();
std::io::stdin().read_line(&mut action_string)?;
if let Ok(parsed_script_action)=action_string.parse::<ScriptActionParseResult>(){
script_action=parsed_script_action;
break;
}else{
print!("action: ");
std::io::Write::flush(&mut std::io::stdout())?;
}
}
//update allowed/replace/blocked
match script_action{
ScriptActionParseResult::Pass => {
//if current.lua was updated, create an allowed and replace file and set script_action to replace(new_id)
let modified_source=std::fs::read_to_string("current.lua")?;
if &modified_source==source{
//it's always new.
//insert allowed_set
allowed_set.insert(modified_source.clone());
//insert allowed_map
allowed_map.insert(id,modified_source.clone());
//write allowed/id.lua
std::fs::write(format!("scripts/allowed/{}.lua",id),modified_source)?;
id+=1;
ScriptAction::Pass
}else{
//insert allowed_set
allowed_set.insert(modified_source.clone());
//insert allowed_map
allowed_map.insert(id,modified_source.clone());
//insert replace_map
replace_map.insert(source.clone(),id);//this cannot be reached if it already exists
//write allowed/id.lua
std::fs::write(format!("scripts/allowed/{}.lua",id),modified_source)?;
//write replace/id.lua
std::fs::write(format!("scripts/replace/{}.lua",id),source)?;
let ret=ScriptAction::Replace(id);
id+=1;
ret
}
},
ScriptActionParseResult::Block => {
blocked.insert(source.clone());
std::fs::write(format!("scripts/blocked/{}.lua",id),source)?;
id+=1;
ScriptAction::Block
},
ScriptActionParseResult::Exit => break 'map_loop,
ScriptActionParseResult::Delete => ScriptAction::Delete,
}
};
let location=get_full_name(&dom, script);
match source_action{
ScriptAction::Pass => println!("passed source location={}",location),
ScriptAction::Replace(replace_id)=>{
//replace the source
if let (Some(replace_source),Some(replace_script))=(allowed_map.get(&replace_id),dom.get_by_ref_mut(script.referent())){
replace_count+=1;
println!("replaced source id={} location={}",replace_id,location);
replace_script.properties.insert("Source".to_string(), rbx_dom_weak::types::Variant::String(replace_source.clone()));
}else{
panic!("failed to get replacement source id={} location={}",replace_id,location);
}
},
ScriptAction::Delete => {
println!("deleted source location={}",location);
replace_count+=1;
dom.destroy(script.referent());
},
ScriptAction::Flag => {
println!("flagged source location={}",location);
fail_type=Interactive::Flagged;
},
ScriptAction::Block => {
block_count+=1;
println!("blocked source location={}",location);
match fail_type{
Interactive::Passed => fail_type=Interactive::Blocked,
_=>(),
}
},
}
}else{
panic!("FATAL: failed to get source for {:?}",file_thing.file_name());
}
}else{
panic!("FATAL: failed to get_by_ref {:?}",script_ref);
}
}
let mut dest=match fail_type{
Interactive::Passed => {
println!("map={:?} passed with {} {}",file_thing.file_name(),script_count,if script_count==1 {"script"}else{"scripts"});
if replace_count==0{
std::path::PathBuf::from("maps/passed")
}else{
//create new file
println!("{} {} replaced - generating new file...",replace_count,if replace_count==1 {"script was"}else{"scripts were"});
let mut dest=std::path::PathBuf::from("maps/passed");
dest.push(file_thing.file_name());
let output = std::io::BufWriter::new(std::fs::File::create(dest)?);
rbx_binary::to_writer(output, &dom, &[dom.root_ref()])?;
//move original to processed folder
std::path::PathBuf::from("maps/unaltered")
}
},//write map into maps/processed
Interactive::Blocked => {
println!("map={:?} blocked with {}/{} {} blocked",file_thing.file_name(),block_count,script_count,if script_count==1 {"script"}else{"scripts"});
std::path::PathBuf::from("maps/blocked")
},//write map into maps/blocked
Interactive::Flagged => {
println!("map={:?} flagged",file_thing.file_name());
std::path::PathBuf::from("maps/flagged")
},//write map into maps/flagged
};
dest.push(file_thing.file_name());
std::fs::rename(file_thing.path(), dest)?;
}
std::fs::write("id",id.to_string())?;
Ok(()) Ok(())
} }
fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Download(map_list)=>download(map_list.maps),
Commands::Upload=>upload(),
Commands::Scan=>scan(),
Commands::Replace=>replace(),
Commands::Interactive=>interactive(),
Commands::Extract(map)=>extract(map.id),
}
}

19
src/prelude.rs Normal file
View File

@ -0,0 +1,19 @@
pub use crate::error::Error;
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
pub type StdResult<T, E> = std::result::Result<T, E>;
// i just wanted to mess around with macros a bit
// so heres labelprint as a macro
#[macro_export]
macro_rules! lprint {
($expr:expr) => {{
let ___this_file = std::file!();
let ___line = std::line!();
// let ___column = column!();
println!("[{}:{}] {}", ___this_file, ___line, $expr);
}};
($expr:expr, $($arg:tt)*) => {{
lprint!(format!($expr, $($arg)*));
}};
}