Created
October 30, 2019 00:48
-
-
Save stravant/a092aaf294dcb85164d0cb915f931f87 to your computer and use it in GitHub Desktop.
Scramble the object placement in an osu map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--X: 0-512 | |
--Y: 0-384 | |
-- Type bits: (-)(-)(-)(-) (spinner)(NC)(slider)(circle) | |
-- Circle: x,y,time,type,hitSound,extras | |
-- Slider: x,y,time,type,hitSound,sliderType|curvePoints,repeat,pixelLength,edgeHitsounds,edgeAdditions,extras | |
-- type = Linear Perfect Bezier Catmul | |
-- Get target file | |
local target = arg[1] | |
if not arg[1] then | |
error("No file") | |
end | |
-- Open file | |
--target = "C:\\Users\\stravant\\AppData\\Local\\osu!\\Songs\\"..target | |
local f = io.open(target) | |
if not f then | |
error("Could not find file") | |
end | |
-- Get lines | |
local lines = {} | |
local objectStart = nil | |
for line in f:lines() do | |
table.insert(lines, line) | |
if line == '[HitObjects]' then | |
objectStart = #lines + 1 | |
elseif line:sub(1,7) == 'Version' then | |
lines[#lines] = 'Version:Randomized' | |
elseif line:sub(1,9) == 'BeatmapID' then | |
lines[#lines] = 'BeatmapID:0' | |
end | |
end | |
-- Object lines | |
local objects = {} | |
local sliders = { | |
L = true; | |
P = true; | |
B = true; | |
} | |
for i = objectStart, #lines do | |
local line = lines[i] | |
local x, y, time, type, snd, extras = line:gmatch("(%d+),(%d+),([^,]+),([^,]+),([^,]+),(.*)")() | |
--print("type:", type) | |
if sliders[extras:sub(1,1)] then | |
local curveType, curvePoints, rest = extras:gmatch("([LPB])([^,]+)(.*)")() | |
local curve = {} | |
for x, y in curvePoints:gmatch("|([%-%d]+):([%-%d]+)") do | |
print(x, y) | |
table.insert(curve, {x = tonumber(x); y = tonumber(y);}) | |
end | |
table.insert(objects, { | |
curve = curve; | |
at = {x = tonumber(x); y = tonumber(y)}; | |
size = { | |
x = math.abs(curve[#curve].x - tonumber(x)); | |
y = math.abs(curve[#curve].y - tonumber(y)); | |
}; | |
format = function(self) | |
local newPoints = "" | |
for _, point in pairs(self.curve) do | |
newPoints = newPoints.."|"..point.x..":"..point.y | |
end | |
return self.at.x..","..self.at.y..","..time..","..type..","..snd..",".. | |
curveType..newPoints..rest | |
end; | |
move = function(self, x, y) | |
local dx = x - self.at.x | |
local dy = y - self.at.y | |
self.at.x = x | |
self.at.y = y | |
for _, p in pairs(self.curve) do | |
p.x = p.x + dx | |
p.y = p.y + dy | |
end | |
end; | |
}) | |
else | |
print(x..','..y) | |
table.insert(objects, { | |
at = {x = tonumber(x); y = tonumber(y)}; | |
size = {x = 0; y = 0}; | |
format = function(self) | |
return self.at.x..","..self.at.y..","..time..","..type..","..snd..","..extras | |
end; | |
move = function(self, x, y) | |
self.at.x = x | |
self.at.y = y | |
end; | |
}) | |
end | |
end | |
-- Modify objects | |
local width = 512 | |
local height = 384 | |
for _, object in pairs(objects) do | |
local widthleft = width - object.size.x | |
local heightleft = height - object.size.y | |
object:move(math.random(1, widthleft), math.random(1, heightleft)) | |
end | |
-- Rewrite | |
local newContent = "" | |
for i = 1, objectStart-1 do | |
newContent = newContent..lines[i].."\n" | |
end | |
for _, object in pairs(objects) do | |
newContent = newContent..object:format().."\n" | |
end | |
local newFile = target:sub(1,-4).."_jumpy.osu" | |
local newFile = io.open(newFile, "w") | |
newFile:write(newContent) | |
newFile:close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment