예제 #1
0
int sod_halt( sod_session *session )
{
	pstart();
	
	if ( session->ecode!=SE_NONE )
	{
		#ifdef USE_GETTEXT
		printf(gettext(vstr("WARNING: unmanaged error:\n\tfunction: %s\n\terror: %s\n\tcode: %d\n", \
			session->errorfunc,session->errortext,session->ecode)));
		#else
		printf(vstr("WARNING: unmanaged error:\n\tfunction: %s\n\terror: %s\n\tcode: %d\n", \
			session->errorfunc,session->errortext,session->ecode));
		#endif
	}
	
	if ( session->status==SOD_CONNECTED )
	{
		sod_disconnect(session);
	}
	
	dfree(session);
	
	pstop();
	return SOD_OK;
}
예제 #2
0
void Shader::addVertexShader(const char *vfile)
{
	std::string vstr(vfile);
	if(vstr.size() != 0){
		m_vs = createShader(GL_VERTEX_SHADER,file_read(vfile));
		glAttachShader(m_Program, m_vs);
		std::cout<<"Vertex Shader \""<< vstr<<"\" Added"<<std::endl;
	}
	else{
		std::cerr<<"No Vertex Shader Detected";
	}
}
예제 #3
0
SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
{
	if (m_IgnoreLevel)
	{
		return SMCResult_Continue;
	}

	switch (m_ParseState)
	{
		case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
		{
			if (!strcmp(key, "type"))
			{
				auto type = FieldType::FIELD_NONE;

				if (!strcmp(value, "stringint"))
				{
					type = FieldType::FIELD_STRINGINT;
				}
				else if (!strcmp(value, "stringptr"))
				{
					type = FieldType::FIELD_STRINGPTR;
				}
				else if (!strcmp(value, "string"))
				{
					type = FieldType::FIELD_STRING;
				}
				else if (!strcmp(value, "classptr"))
				{
					type = FieldType::FIELD_CLASSPTR;
				}
				else if (!strcmp(value, "class"))
				{
					type = FieldType::FIELD_CLASS;
				}
				else if (!strcmp(value, "ehandle"))
				{
					type = FieldType::FIELD_EHANDLE;
				}
				else if (!strcmp(value, "edict"))
				{
					type = FieldType::FIELD_EDICT;
				}
				else if (!strcmp(value, "entvars"))
				{
					type = FieldType::FIELD_ENTVARS;
				}
				else if (!strcmp(value, "vector"))
				{
					type = FieldType::FIELD_VECTOR;
				}
				else if (!strcmp(value, "pointer"))
				{
					type = FieldType::FIELD_POINTER;
				}
				else if (!strcmp(value, "integer"))
				{
					type = FieldType::FIELD_INTEGER;
				}
				else if (!strcmp(value, "function"))
				{
					type = FieldType::FIELD_FUNCTION;
				}
				else if (!strcmp(value, "boolean"))
				{
					type = FieldType::FIELD_BOOLEAN;
				}
				else if (!strcmp(value, "short"))
				{
					type = FieldType::FIELD_SHORT;
				}
				else if (!strcmp(value, "character"))
				{
					type = FieldType::FIELD_CHARACTER;
				}
				else if (!strcmp(value, "float"))
				{
					type = FieldType::FIELD_FLOAT;
				}

				TempType.fieldType = type;
			}
			else if (!strcmp(key, "size"))
			{
				TempType.fieldSize = ke::Max<int>(0, atoi(value));
			}
			else if (!strcmp(key, "unsigned"))
			{
				TempType.fieldUnsigned = !!atoi(value);
			}
			else if (g_LibSys.IsPlatformCompatible(key, &m_MatchedPlatform))
			{
				m_FoundOffset = true;
				TempType.fieldOffset = atoi(value);
			}
			break;
		}
		case PSTATE_GAMEDEFS_KEYS:
		{
			ke::AString vstr(value);
			m_Keys.replace(key, ke::Move(vstr));
			break;
		}
		case PSTATE_GAMEDEFS_SUPPORTED:
		{
			if (strcmp(key, "game") == 0)
			{
				m_HadGame = true;

				if (DoesGameMatch(value))
				{
					m_MatchedGame = true;
				}

				if ((!m_HadEngine && m_MatchedGame) || (m_MatchedEngine && m_MatchedGame))
				{
					m_ShouldBeReadingDefault = true;
				}
			}
			else if (strcmp(key, "engine") == 0)
			{
				m_HadEngine = true;

				if (DoesEngineMatch(value))
				{
					m_MatchedEngine = true;
				}

				if ((!m_HadGame && m_MatchedEngine) || (m_MatchedGame && m_MatchedEngine))
				{
					m_ShouldBeReadingDefault = true;
				}
			}
			break;
		}
		case PSTATE_GAMEDEFS_SIGNATURES_SIG:
		{
			if (g_LibSys.IsPlatformCompatible(key, &m_MatchedPlatform))
			{
				strncopy(TempSig.signature, value, sizeof(TempSig.signature));
			}
			else if (strcmp(key, "library") == 0)
			{
				strncopy(TempSig.library, value, sizeof(TempSig.library));
			}
			break;
		}
		case PSTATE_GAMEDEFS_ADDRESSES_ADDRESS:
		case PSTATE_GAMEDEFS_ADDRESSES_ADDRESS_READ:
		{
			if (strcmp(key, "read") == 0)
			{
				int limit = sizeof(m_AddressRead) / sizeof(m_AddressRead[0]);

				if (m_AddressReadCount < limit)
				{
					m_AddressRead[m_AddressReadCount] = atoi(value);
					m_AddressReadCount++;
				}
				else
				{
					AMXXLOG_Error("[SM] Error parsing Address \"%s\", does not support more than %d read offsets (gameconf \"%s\")",
								  m_Address, limit, m_CurrentPath);
				}
			}
			else if (strcmp(key, "signature") == 0)
			{
				strncopy(m_AddressSignature, value, sizeof(m_AddressSignature));
			}
			break;
		}
		case PSTATE_GAMEDEFS_CUSTOM:
		{
			return m_CustomHandler->ReadSMC_KeyValue(states, key, value);
		}
	}

	return SMCResult_Continue;
}
예제 #4
0
SMCResult CGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
{
	if (m_IgnoreLevel)
	{
		return SMCResult_Continue;
	}

	switch (m_ParseState)
	{
		case PSTATE_GAMEDEFS_OFFSETS_OFFSET:
		{
			if (g_LibSys.IsPlatformCompatible(key, &m_MatchedPlatform))
			{
				if (m_Class[0])
				{
					auto ic = m_OffsetsByClass.findForAdd(m_Class);

					if (ic.found())
					{
						ic->value->list.replace(m_Offset, atoi(value));
					}
					else if (m_OffsetsByClass.add(ic, m_Class))
					{
						ic->value = new OffsetClass;
						ic->value->list.insert(m_Offset, atoi(value));
					}
				}
				else
				{
					m_Offsets.replace(m_Offset, atoi(value));
				}
			}
			break;
		}
		case PSTATE_GAMEDEFS_KEYS:
		{
			ke::AString vstr(value);
			m_Keys.replace(key, ke::Move(vstr));
			break;
		}
		case PSTATE_GAMEDEFS_SUPPORTED:
		{
			if (strcmp(key, "game") == 0)
			{
				m_HadGame = true;

				if (DoesGameMatch(value))
				{
					m_MatchedGame = true;
				}

				if ((!m_HadEngine && m_MatchedGame) || (m_MatchedEngine && m_MatchedGame))
				{
					m_ShouldBeReadingDefault = true;
				}
			}
			else if (strcmp(key, "engine") == 0)
			{
				m_HadEngine = true;

				if (DoesEngineMatch(value))
				{
					m_MatchedEngine = true;
				}

				if ((!m_HadGame && m_MatchedEngine) || (m_MatchedGame && m_MatchedEngine))
				{
					m_ShouldBeReadingDefault = true;
				}
			}
			break;
		}
		case PSTATE_GAMEDEFS_SIGNATURES_SIG:
		{
			if (g_LibSys.IsPlatformCompatible(key, &m_MatchedPlatform))
			{
				strncopy(TempSig.signature, value, sizeof(TempSig.signature));
			}
			else if (strcmp(key, "library") == 0)
			{
				strncopy(TempSig.library, value, sizeof(TempSig.library));
			}
			break;
		}
		case PSTATE_GAMEDEFS_ADDRESSES_ADDRESS:
		case PSTATE_GAMEDEFS_ADDRESSES_ADDRESS_READ:
		{
			if (strcmp(key, "read") == 0)
			{
				int limit = sizeof(m_AddressRead) / sizeof(m_AddressRead[0]);

				if (m_AddressReadCount < limit)
				{
					m_AddressRead[m_AddressReadCount] = atoi(value);
					m_AddressReadCount++;
				}
				else
				{
					AMXXLOG_Error("[SM] Error parsing Address \"%s\", does not support more than %d read offsets (gameconf \"%s\")",
								  m_Address, limit, m_CurrentPath);
				}
			}
			else if (strcmp(key, "signature") == 0)
			{
				strncopy(m_AddressSignature, value, sizeof(m_AddressSignature));
			}
			break;
		}
		case PSTATE_GAMEDEFS_CUSTOM:
		{
			return m_CustomHandler->ReadSMC_KeyValue(states, key, value);
		}
	}

	return SMCResult_Continue;
}
예제 #5
0
파일: twirl.c 프로젝트: malie/twirl
void
encodeToCNF() {

#define clause2(a,b)				\
  ({add_lit(a); add_lit(b); add_lit(0);})

#define clause3(a,b,c)					\
  ({add_lit(a); add_lit(b); add_lit(c); add_lit(0);})

#define implies(a,b)  clause2(-a, b);
#define implies_or(a,b,c) clause3(-a, b, c);
  
  int f, d, l, t, e, c, r;
  
  for (f = 0; f < S2; f++) {

    clause3(white(f), black(f), nblack(f));
    implies(white(f), -black(f));
    implies(white(f), -nblack(f));
    implies(nblack(f), -black(f));
    implies(nblack(f), -white(f));
    implies(black(f), -white(f));
    implies(black(f), -nblack(f));

    
    implies(white(f), numfield(f));
    implies(nblack(f), xblack(f));
    implies(nblack(f), numfield(f));
    implies(black(f), xblack(f));

    
    implies(white(f), -xblack(f));
    
    implies(black(f), -numfield(f));
    implies(xblack(f), -white(f));
    implies(numfield(f), -black(f));
    implies_or(numfield(f), white(f), nblack(f));
    implies_or(xblack(f), black(f), nblack(f));


    for (d = 0; d < S; d++) {
      implies(num(f,d), numfield(f));

      for (e = 0; e < S; e++) {
	// each digit at most once in each row
	t = same_row_but(f, e);
	if (t != f)
	  implies(num(f, d), -num(t, d));

	// each digit at most once in each column
	t = same_col_but(f, e);
	if (t != f)
	  implies(num(f, d), -num(t, d));

	// only one digit at most in each cell
	if (d != e)
	  implies(num(f, d), -num(f, e));
      }
    }
    // numfield(f) => exists d . num(f,d)
    add_lit(-numfield(f));
    for (d = 0; d < S; d++)
      add_lit(num(f, d));
    add_lit(0);

    // no single white fields
    int c = field_col(f);
    int r = field_row(f);
    add_lit(-white(f));
    if (c >= 1)
      add_lit(-xblack(field(c-1, r)));
    if (c < S-1)
      add_lit(-xblack(field(c+1, r)));
    if (r >= 1)
      add_lit(-xblack(field(c, r-1)));
    if (r < S-1)
      add_lit(-xblack(field(c, r+1)));
    add_lit(0);
  }

  
  
  // Encoding the straights:
  // A constellation like B W W W B is a straight of len 3,
  // when there are no blacks in between.
  // The two B's can also be the border.
  // Only straights of a length >= 2 are interesting.
  // The implications are encoded into clauses like this:
  //    a&b => x
  //    -(a&b) | x
  //    -a | -b | x

  for (f = 0; f < S2; f++) {
    int col = field_col(f);
    int row = field_row(f);
    for (c = col+1; c < S; c++) {
      // col is the first column
      // c is the last column (inclusively)
      int len = c-col+1;
      if (col > 0)
	add_lit(-xblack(same_row_but(f, col-1)));
      if (c <= S-2)
	add_lit(-xblack(same_row_but(f, c+1)));
      for (int s = 0; s < len; s++)
	add_lit(-white(same_row_but(f, col+s)));
      add_lit(hstr(f, len));
      add_lit(0);

      if (col > 0)
	implies(hstr(f,len), xblack(same_row_but(f, col-1)));
      if (c <= S-2)
	implies(hstr(f,len), xblack(same_row_but(f, c+1)));
      for (int s = 0; s < len; s++)
	implies(hstr(f,len), white(same_row_but(f, col+s)));

      // hstr(f,len) => hstrd(f,len,0) | hstrd(f,len,1) ...
      add_lit(-hstr(f, len));
      int largest_mind = S-len;
      for (int mind = 0; mind <= largest_mind; mind++)
	add_lit(hstrd(f, len, mind));
      add_lit(0);

      // hstrd(f,len,d) => num(f,d) | num(f,d+1) ...
      // for all the num()'s in the straight
      for (int sc = col; sc <= c; sc++) {
	int ff = same_row_but(f, sc);
	for (int mind = 0; mind <= largest_mind; mind++) {
	  add_lit(-hstrd(f, len, mind));
	  for (int dig = 0; dig < len; dig++)
	    add_lit(num(ff, mind+dig));
	  add_lit(0);
	}
      }
    }

    for (r = row+1; r < S; r++) {
      int len = r-row+1;
      if (row > 0)
	add_lit(-xblack(same_col_but(f, row-1)));
      if (r <= S-2)
	add_lit(-xblack(same_col_but(f, r+1)));
      for (int s = 0; s < len; s++)
	add_lit(-white(same_col_but(f, row+s)));
      add_lit(vstr(f, len));
      add_lit(0);

      if (row > 0)
	implies(vstr(f,len), xblack(same_col_but(f, row-1)));
      if (r <= S-2)
	implies(vstr(f,len), xblack(same_col_but(f, r+1)));
      for (int s = 0; s < len; s++)
	implies(vstr(f,len), white(same_col_but(f, row+s)));

      
      // and the vstr(f,len) def
      add_lit(-vstr(f, len));
      int largest_mind = S-len;
      for (int mind = 0; mind <= largest_mind; mind++)
	add_lit(vstrd(f, len, mind));
      add_lit(0);

      // vstrd(f,len,d) => num(f,d) | num(f,d+1) ...
      // for all the num()'s in the straight
      for (int sc = row; sc <= r; sc++) {
	int ff = same_col_but(f, sc);
	for (int mind = 0; mind <= largest_mind; mind++) {
	  add_lit(-vstrd(f, len, mind));
	  for (int dig = 0; dig < len; dig++)
	    add_lit(num(ff, mind+dig));
	  add_lit(0);
	}
      }
    }
  }
  printf("encoded into %i clauses\n", clausesptr);
}
예제 #6
0
파일: twirl.c 프로젝트: malie/twirl
void
printResults(PicoSAT *p, int* fields) {
  
  int verbose = 0;
  int y, x, d;
  for (y = 0; y < S; y++) {
    for (x = 0; x < S; x++) {
      int f = field(x, y);

      if (picosat_deref(p, black(f)) == 1)
	printf("B");
      else if (picosat_deref(p, nblack(f)) == 1)
	printf("N");
      /* else if (verbose && picosat_deref(p, numfield(f)) == 1) */
      /* 	printf("#"); */
      else if (verbose && picosat_deref(p, white(f)) == 1)
	printf("w");
      else 
	printf(" ");

      if (fields)
	printf("%c", fields[f] ? '.' : ' ');

      if (verbose) {
	if (picosat_deref(p, xblack(f)) == 1)
	  printf("x");
	else
	  printf(" ");}

      int fo = 0;
      for (d = 0; d < S; d++) {
	if (picosat_deref(p, num(f, d)) == 1) {
	  printf("%i", 1+d);
	  fo++;}}
      if (fo == 0) {
	printf("_");
	fo+=1;}
      while (fo < 2) {
	printf(" ");
	fo++;}
      
      printf(" ");
    }
    printf("\n");
  }
  return;
  for (int row = 0; row < S; row++) {
    for (int col = 0; col < S; col++) {
      for (int len = 2; len < S-col; len++) {
	if (picosat_deref(p, hstr(field(col, row), len)))
	  printf("hstr(field(%i,%i), %i) -> 1\n", col, row, len);
      }
    }
  }
  printf("\n");
  for (int row = 0; row < S; row++) {
    for (int col = 0; col < S; col++) {
      for (int len = 2; len < S-row; len++) {
	if (picosat_deref(p, vstr(field(col, row), len)))
	  printf("vstr(field(%i,%i), %i) -> 1\n", col, row, len);
      }
    }
  }
}