Skip to content

Instantly share code, notes, and snippets.

@pckv
Last active May 25, 2018 11:47
Show Gist options
  • Save pckv/8f4f62ddb409aa37cf8b6cdeb17b90da to your computer and use it in GitHub Desktop.
Save pckv/8f4f62ddb409aa37cf8b6cdeb17b90da to your computer and use it in GitHub Desktop.
splits the given beatmap by combo, returns multiple txt files of hitobjects. requires Lua BitOP
--[[ LICENSE
The MIT License (MIT)
Copyright (c) 2016 PC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
HOW TO USE:
• setup lua and install BitOP (find some tutorial online)
• run this file in a lua session and input the beatmap path and the number of
difficulties (players in tag coop) to split
• open the map in osu!, go to File > Create a new Difficulty...
• enter a name for your diff (e.g "player 1") and click OK, followed by clicking Yes
• go to File > Open .osu in Notepad
• under the [HitObjects] section, paste the contents of the corresponding txt file
output by the script
• repeat until done!
--]]
require "bit"
band = bit.band
content = {}
objects = {}
combos = {}
fileName = ""
players = 4
-- Values for writing file
objectStart = 0
objectEnd = 0
-- Constants
CIRCLE = 1
SLIDER = 2
NEW_COMBO = 4
SPINNER = 8
-- Imports the .osu content
function importFile(name)
local file = io.open(name, "r")
for line in file:lines() do
table.insert(content, line)
end
file:close()
end
-- Returns subgroup string data in a table
function getData(group)
local data = {}
local start = false
for i=1, #content do
if content[i-1] == "["..group.."]" then
start = true
objectStart = i+1
end
if start then
if (content[i] == "") or (content[i]:sub(1,1) == "[") then
objectEnd = i
break
end
table.insert(data, content[i])
end
end
return data
end
-- Gathers individual information on hitobjects
function getHitObjects()
local data = getData("HitObjects")
-- Capture hitobject info from each line
for i=1,#data do
local values = {}
for v in data[i]:gmatch("([^,]+),?") do
table.insert(values, v)
end
-- Assign values to objects
local o = {
x = tonumber(values[1]),
y = tonumber(values[2]),
time = tonumber(values[3]),
object = tonumber(values[4]),
hitSound = tonumber(values[5])
}
if band(o.object, CIRCLE) == CIRCLE then
o.addition = values[6]
elseif band(o.object, SLIDER) == SLIDER then
local sliderInfo = values[6]
for i=7,#values-1 do
sliderInfo = sliderInfo..","..values[i]
end
o.slider = sliderInfo
o.addition = values[#values]
-- Spinner
elseif band(o.object, SPINNER) == SPINNER then
o.endTime = tonumber(values[6])
o.addition = values[7]
end
table.insert(objects, o)
end
end
-- Returns true if new combo
function isNewCombo(i)
if band(objects[i].object, NEW_COMBO) == NEW_COMBO then
return true
end
return false
end
-- Collect combo starting points
function getCombos()
for i=1,#objects do
if isNewCombo(i) then
table.insert(combos, i)
end
end
end
-- Splits combos from the 1th, 2nd, 3rd, or 4th combo and returns hitobject information of these combos
function splitCombos(offset)
local newObjects = {}
local count = players-(offset-1) -- Starts counting from respective combo
for i=1,#combos do
-- Include spinners
if band(objects[combos[i]].object, SPINNER) == SPINNER then
table.insert(newObjects, objects[combos[i]])
else
if count % players == 0 then
local endCombo = 0
if combos[i+1] then
endCombo = combos[i+1]-1
else
endCombo = #objects
end
for j=combos[i], endCombo do
table.insert(newObjects, objects[j])
end
end
count = count + 1
end
end
return newObjects
end
function objectToString(o)
local s = string.format("%d,%d,%d,%d,%d",
o.x,
o.y,
o.time,
o.object,
o.hitSound
)
if band(o.object, SLIDER) == SLIDER then
s = s..","..o.slider
elseif band(o.object, SPINNER) == SPINNER then
s = s..","..o.endTime
end
if o.addition then
s = s..","..o.addition
end
return s
end
-- Currently: writes hitobject data to file
function writeFile(data, name)
local file = io.open(name, "w")
for i=1,#data do
file:write(objectToString(data[i]).."\n")
end
file:close()
end
--[[ Program Start ]]--
io.write("Please input file path: ")
fileName = io.read()
io.write("Players included: ")
players = tonumber(io.read())
importFile(fileName)
getHitObjects()
getCombos()
for player=1,players do
local combo = splitCombos(player)
writeFile(combo, "hitobjects_"..player..".txt")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment