bool WLEMMCommandProcessor::process( WLEMMCommand::SPtr cmdIn )
{
    bool succes;
    switch( cmdIn->getCommand() )
    {
        case WLEMMCommand::Command::COMPUTE:
            wlog::debug( CLASS ) << "Processing Command::COMPUTE";
            succes = processCompute( cmdIn->getEmm() );
            break;
        case WLEMMCommand::Command::INIT:
            wlog::debug( CLASS ) << "Processing Command::INIT";
            succes = processInit( cmdIn );
            break;
        case WLEMMCommand::Command::MISC:
            wlog::debug( CLASS ) << "Processing Command::MISC";
            succes = processMisc( cmdIn );
            break;
        case WLEMMCommand::Command::TIME_UPDATE:
            wlog::debug( CLASS ) << "Processing Command::TIME_UPDATE";
            succes = processTime( cmdIn );
            break;
        case WLEMMCommand::Command::RESET:
            wlog::debug( CLASS ) << "Processing Command::RESET";
            succes = processReset( cmdIn );
            break;
        default:
            wlog::error( CLASS ) << "Unknown Command::Enum!";
            succes = false;
    }
    if( !succes )
    {
        wlog::error( CLASS ) << "Error on processing command:\n" << *cmdIn;
    }
    return succes;
}
示例#2
0
static void runRMXPScripts(BacktraceData &btData)
{
	const Config &conf = shState->rtData().config;
	const std::string &scriptPack = conf.game.scripts;

	if (scriptPack.empty())
	{
		showMsg("No game scripts specified (missing Game.ini?)");
		return;
	}

	if (!shState->fileSystem().exists(scriptPack.c_str()))
	{
		showMsg("Unable to open '" + scriptPack + "'");
		return;
	}

	VALUE scriptArray;

	/* We checked if Scripts.rxdata exists, but something might
	 * still go wrong */
	try
	{
		scriptArray = kernelLoadDataInt(scriptPack.c_str(), false);
	}
	catch (const Exception &e)
	{
		showMsg(std::string("Failed to read script data: ") + e.msg);
		return;
	}

	if (!RB_TYPE_P(scriptArray, RUBY_T_ARRAY))
	{
		showMsg("Failed to read script data");
		return;
	}

	rb_gv_set("$RGSS_SCRIPTS", scriptArray);

	long scriptCount = RARRAY_LEN(scriptArray);

	std::string decodeBuffer;
	decodeBuffer.resize(0x1000);

	for (long i = 0; i < scriptCount; ++i)
	{
		VALUE script = rb_ary_entry(scriptArray, i);

		if (!RB_TYPE_P(script, RUBY_T_ARRAY))
			continue;

		VALUE scriptName   = rb_ary_entry(script, 1);
		VALUE scriptString = rb_ary_entry(script, 2);

		int result = Z_OK;
		unsigned long bufferLen;

		while (true)
		{
			unsigned char *bufferPtr =
			        reinterpret_cast<unsigned char*>(const_cast<char*>(decodeBuffer.c_str()));
			const unsigned char *sourcePtr =
			        reinterpret_cast<const unsigned char*>(RSTRING_PTR(scriptString));

			bufferLen = decodeBuffer.length();

			result = uncompress(bufferPtr, &bufferLen,
			                    sourcePtr, RSTRING_LEN(scriptString));

			bufferPtr[bufferLen] = '\0';

			if (result != Z_BUF_ERROR)
				break;

			decodeBuffer.resize(decodeBuffer.size()*2);
		}

		if (result != Z_OK)
		{
			static char buffer[256];
			snprintf(buffer, sizeof(buffer), "Error decoding script %ld: '%s'",
			         i, RSTRING_PTR(scriptName));

			showMsg(buffer);

			break;
		}

		rb_ary_store(script, 3, rb_str_new_cstr(decodeBuffer.c_str()));
	}

	/* Execute preloaded scripts */
	for (std::set<std::string>::iterator i = conf.preloadScripts.begin();
	     i != conf.preloadScripts.end(); ++i)
		runCustomScript(*i);

	VALUE exc = rb_gv_get("$!");
	if (exc != Qnil)
		return;

	while (true)
	{
		for (long i = 0; i < scriptCount; ++i)
		{
			VALUE script = rb_ary_entry(scriptArray, i);
			VALUE scriptDecoded = rb_ary_entry(script, 3);
			VALUE string = newStringUTF8(RSTRING_PTR(scriptDecoded),
			                             RSTRING_LEN(scriptDecoded));

			VALUE fname;
			const char *scriptName = RSTRING_PTR(rb_ary_entry(script, 1));
			char buf[512];
			int len;

			if (conf.useScriptNames)
				len = snprintf(buf, sizeof(buf), "%03ld:%s", i, scriptName);
			else
				len = snprintf(buf, sizeof(buf), SCRIPT_SECTION_FMT, i);

			fname = newStringUTF8(buf, len);
			btData.scriptNames.insert(buf, scriptName);

			int state;
			evalString(string, fname, &state);
			if (state)
				break;
		}

		VALUE exc = rb_gv_get("$!");
		if (rb_obj_class(exc) != getRbData()->exc[Reset])
			break;

		processReset();
	}
}