Downloads containing UIDCollisionFinder.mut

Downloads
Name Author Game Mode Rating
JJ2+ Only: UID Collision Finder Violet CLM Mutator N/A Download file

File preview

#pragma name "UID Collision Finder"


const int EventPositionIndexing = 1; //set to 0 to use JJ2 positions, or to 1 to use JCS positions


const uint levelWidth = jjLayerWidth[4];
array<string> EventNames(256, "Event");

class Object {
	uint8 eventID;
	int xTile, yTile;
	Object(){}
	Object(uint8 e, int x, int y) { eventID = e; xTile = x; yTile = y; }
	string opImplConv() const { 
		return "" + EventNames[eventID] + " at " + (xTile+EventPositionIndexing) + "," + (yTile+EventPositionIndexing);
	}
}
array<Object@> Objects(0x10000, null);
uint Collisions = 0;

uint16 getUID (uint8 e, uint x, uint y) {
	return ((e << 10) + x + levelWidth * y) & 0x7FFF;
}
bool testCollision(uint8 eventID, uint x, uint y) {
	const auto UID = getUID(eventID, x, y);
	Object@ oldObject = Objects[UID];
	if (oldObject !is null) {
		jjDebug("Potential collision between " + oldObject + " and " + Object(eventID, x, y));
		Collisions += 1;
		return true;
	} else {
		@Objects[UID] = Object(eventID, x, y);
		return false;
	}
}

void onLevelLoad() {
	jjSTREAM ini("JCS.ini");
	for (uint i = 0; i < EventNames.length; ++i)
		EventNames[i] += " #" + i;
	if (ini.getSize() > 0) {
		string line;
		array<string> results;
		bool hasFoundEventsSection = false;
		while (ini.getLine(line) || line.length > 0) {
			if (jjRegexMatch(line, "\\s*\\[(.+)\\]\\s*", results)) {
				if (results[1] == "Events")
					hasFoundEventsSection = true;
				else if (hasFoundEventsSection)
					break;
			} else if (hasFoundEventsSection && jjRegexSearch(line, "(\\d+)=(.*?)\\s+\\|.*", results)) {
				EventNames[parseInt(results[1])] = '"' + results[2] + '"';
			}
		}
	}
	
	for (uint x = 0; x < levelWidth; ++x)
		for (uint y = 0; y < uint(jjLayerHeight[4]); ++y) {
			const uint8 eventID = jjEventGet(x, y);
			if (eventID > 32 && jjObjectPresets[eventID].isActive) {
				testCollision(eventID, x, y);
				if (eventID == OBJECT::GENERATOR)
					testCollision(jjParameterGet(x, y, 0, 8), x, y);
			}
		}
	if (Collisions == 0)
		jjAlert("Congratulations! Your level is safe.", false, STRING::MEDIUM);
	else
		jjAlert("|" + Collisions + " potential UID collision/s found!", false, STRING::MEDIUM);
}