/* ---------------------------------------------------------------------------- * Reads the provided script variables, if any, and does stuff with them. */ void pikmin::read_script_vars(const string &vars) { mob::read_script_vars(vars); maturity = s2i(get_var_value(vars, "maturity", "2")); if(s2b(get_var_value(vars, "sprout", "0"))) { fsm.first_state_override = PIKMIN_STATE_SPROUT; } }
/* ---------------------------------------------------------------------------- * Creates a Pikmin. */ pikmin::pikmin(const float x, const float y, pikmin_type* type, const float angle, const string &vars) : mob(x, y, type, angle, vars) { pik_type = type; hazard_time_left = -1; attacking_mob = NULL; latched = false; attack_time = 0; being_chomped = false; carrying_mob = NULL; wants_to_carry = NULL; pluck_reserved = false; team = MOB_TEAM_PLAYER_1; // TODO maturity = s2i(get_var_value(vars, "maturity", "2")); if(s2b(get_var_value(vars, "buried", "0"))) state = PIKMIN_STATE_BURIED; }
int main(int argc, char **argv) { if (argc == 1) help(argv[0]); printf("command:"); for (int i = 0; i < argc; i++) printf(" %s", argv[i]); printf("\n\n"); static const char *optstring = "i:o:r:b:l:dt:h"; static struct option longopts[] = { {"input", required_argument, NULL, 'i'}, {"output", required_argument, NULL, 'o'}, {"initial-raw-block-size", required_argument, NULL, 'r'}, {"block-size", required_argument, NULL, 'b'}, {"length-threshold", required_argument, NULL, 'l'}, {"dynamic-threshold", no_argument, NULL, 'd'}, {"threads", required_argument, NULL, 't'}, {"help", no_argument, NULL, 'h'}, { NULL, 0, NULL, 0 } }; char default_output[BUFSIZ]; time_t t; time(&t); strftime(default_output, BUFSIZ, "encode.output.%Y%m%d%H%M%S", localtime(&t)); char *input = NULL; char *output = default_output; size_t raw_block_size = s2b(DEFAULT_RAW_BLOCK_SIZE); size_t block_size = s2b(DEFAULT_BLOCK_SIZE); size_t length_threshold = DEFAULT_LENGTH_THRESHOLD; size_t dynamic_threshold = DEFAULT_DYNAMIC_THRESHOLD; size_t threads = DEFAULT_THREAD_COUNT; int opt; while ((opt = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) { switch (opt) { case 'i': input = optarg; break; case 'o': output = optarg; break; case 'r': raw_block_size = s2b(optarg); break; case 'b': block_size = s2b(optarg); break; case 'l': length_threshold = s2b(optarg); break; case 'd': dynamic_threshold = true; break; case 't': threads = s2b(optarg); break; case 'h': help(argv[0]); break; } } if (input == NULL) { fprintf(stderr, "Error: Input file required\n"); exit(EXIT_FAILURE); } Encode encode( raw_block_size, block_size, threads, length_threshold, dynamic_threshold, input, output ); encode.run(); return EXIT_SUCCESS; }
/* ---------------------------------------------------------------------------- * Reads a child node's value, and uses it to set a variable. * Will not do anything if the child's value is empty. * child: Name of the child node. * var: The var to set. This is a boolean. */ void reader_setter::set(const string &child, bool &var) { string s = node->get_child_by_name(child)->value; if(s.empty()) return; var = s2b(s); }
/* ---------------------------------------------------------------------------- * Loads data about the Pikmin type from a data file. */ void pikmin_type::load_from_file( data_node* file, const bool load_resources, vector<pair<size_t, string> >* anim_conversions ) { attack_power = s2f(file->get_child_by_name("attack_power")->value); attack_interval = s2f( file->get_child_by_name( "attack_interval" )->get_value_or_default("0.8") ); throw_height_mult = s2f( file->get_child_by_name( "throw_height_mult" )->get_value_or_default("1") ); can_carry_bomb_rocks = s2b( file->get_child_by_name("can_carry_bomb_rocks")->value ); can_dig = s2b(file->get_child_by_name("can_dig")->value); can_latch = s2b(file->get_child_by_name("can_latch")->value); can_swim = s2b(file->get_child_by_name("can_swim")->value); carry_speed = s2f(file->get_child_by_name("carry_speed")->value); carry_strength = s2f(file->get_child_by_name("carry_strength")->value); has_onion = s2b(file->get_child_by_name("has_onion")->value); data_node* hazards_node = file->get_child_by_name("resistances"); vector<string> hazards_strs = semicolon_list_to_vector(hazards_node->value); for(size_t h = 0; h < hazards_strs.size(); ++h) { string hazard_name = hazards_strs[h]; if(hazards.find(hazard_name) == hazards.end()) { log_error("Unknown hazard \"" + hazard_name + "\"!", hazards_node); } else { resistances.push_back(&(hazards[hazard_name])); } } if(load_resources) { bmp_top[0] = bitmaps.get(file->get_child_by_name("top_leaf")->value, file); bmp_top[1] = bitmaps.get(file->get_child_by_name("top_bud")->value, file); bmp_top[2] = bitmaps.get(file->get_child_by_name("top_flower")->value, file); bmp_icon = bitmaps.get(file->get_child_by_name("icon")->value, file); bmp_maturity_icon[0] = bitmaps.get(file->get_child_by_name("icon_leaf")->value, file); bmp_maturity_icon[1] = bitmaps.get(file->get_child_by_name("icon_bud")->value, file); bmp_maturity_icon[2] = bitmaps.get(file->get_child_by_name("icon_flower")->value, file); } anim_conversions->push_back(make_pair(PIKMIN_ANIM_IDLING, "idling")); anim_conversions->push_back(make_pair(PIKMIN_ANIM_WALKING, "walking")); anim_conversions->push_back(make_pair(PIKMIN_ANIM_THROWN, "thrown")); anim_conversions->push_back(make_pair(PIKMIN_ANIM_ATTACKING, "attacking")); anim_conversions->push_back(make_pair(PIKMIN_ANIM_GRABBING, "grabbing")); anim_conversions->push_back(make_pair(PIKMIN_ANIM_SIGHING, "sighing")); anim_conversions->push_back(make_pair(PIKMIN_ANIM_CARRYING, "carrying")); anim_conversions->push_back(make_pair(PIKMIN_ANIM_BURIED, "buried")); anim_conversions->push_back(make_pair(PIKMIN_ANIM_PLUCKING, "plucking")); anim_conversions->push_back(make_pair(PIKMIN_ANIM_LYING, "lying")); pikmin_in_onions[this] = s2i(file->get_child_by_name("onion_starting_number")->value); }
int SWMIopnexec (state_t *sp) { char q[1024], opnstr[1024], *name, *origname, *s; opn_t *opnp, *opnbasep, *opntimep, *opnfreqp; obj_t *objp; HRESULT hr; BSTR propb, ctb, wqlb, qb; SAFEARRAY *props; VARIANT var; LONG pu, pl, pi; ULONG ul; double v; kvt_t *kvtp; int kvti; ctb = s2b ("countertype"); wqlb = s2b ("WQL"); for ( objp = (obj_t *) dtfirst (objdict); objp; objp = (obj_t *) dtnext (objdict, objp) ) { sfsprintf (q, 1024, "select * from %s", objp->obj); if (verbose) sfprintf (sfstderr, "query: %s\n", q); if (!(qb = s2b (q))) { sfprintf (sfstderr, "cannot convert obj name %s to bstr\n", objp->obj); return -1; } if ((hr = sp->pSvc->ExecQuery ( wqlb, qb, WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 0, &sp->pEnum )) != S_OK) { sfprintf ( sfstderr, "cannot execute query %s, error %s\n", q, E2ccp (hr) ); return -1; } if (SWMIproxysecurity (sp, sp->pEnum) < 0) { sfprintf (sfstderr, "cannot enable security for query %s\n", q); return -1; } while ( sp->pEnum->Next (30 * 1000, 1, &sp->pClsObj, &ul ) == S_OK && ul == 1) { if ((hr = sp->pClsObj->GetNames ( 0, WBEM_FLAG_ALWAYS | WBEM_FLAG_NONSYSTEM_ONLY, 0, &props )) != S_OK) { sfprintf ( sfstderr, "cannot get props for obj %s, error %s\n", objp->obj, E2ccp (hr) ); return -1; } if( (hr = SafeArrayGetLBound (props, 1, &pl)) != S_OK || (hr = SafeArrayGetUBound (props, 1, &pu)) != S_OK ) { sfprintf ( sfstderr, "cannot get props bounds for %s, error %s\n", objp->obj, E2ccp (hr) ); return -1; } if (pu - pl + 1 > kvtn) { kvtn = pu - pl + 1; if (!(kvts = (kvt_t *) vmresize ( Vmheap, kvts, kvtn * sizeof (kvt_t), VM_RSCOPY ))) { sfprintf (sfstderr, "cannot grow kvt array\n"); return -1; } } name = NULL; for (pi = pl, kvtl = 0; pi <= pu; pi++, kvtl++) { kvtp = &kvts[kvtl]; if ((hr = SafeArrayGetElement (props, &pi, &propb)) != S_OK) { sfprintf ( sfstderr, "cannot get prop name for %d/%s, error %s\n", pi, objp->obj, E2ccp (hr) ); continue; } kvtp->kp = (char *) b2s (propb); if ((hr = sp->pClsObj->Get (propb, 0, &var, 0, 0)) != S_OK) { sfprintf ( sfstderr, "cannot get prop value for %d/%s, error %s\n", pi, objp->obj, E2ccp (hr) ); continue; } if ( !(kvtp->vp = (char *) V2ccp (&var)) || !(kvtp->vp = vmstrdup (Vmheap, kvtp->vp)) ) { kvtl--; continue; } switch (var.vt) { case VT_UI1: kvtp->v = var.bVal; break; case VT_I2: kvtp->v = var.iVal; break; case VT_I4: kvtp->v = var.lVal; break; default: kvtp->v = strtoull (kvtp->vp, &s, 10); break; } if (strcmp (kvtp->kp, "Name") == 0) { if (var.vt == VT_NULL) name = "ALL"; else name = kvtp->vp; origname = name; } if ((hr = sp->pClsObj->GetPropertyQualifierSet ( propb, &sp->pQualSet )) != S_OK) { sfprintf ( sfstderr, "cannot get quals for %d/%s, error %s\n", pi, objp->obj, E2ccp (hr) ); continue; } kvtp->type = V_TYPE_STRING; if ((hr = sp->pQualSet->Get ( ctb, 0, &var, 0 )) == S_OK && var.vt == VT_I4) { switch (var.lVal) { case PERF_COUNTER_RAWCOUNT: case PERF_COUNTER_LARGE_RAWCOUNT: kvtp->type = V_TYPE_SIMPLE; break; case PERF_RAW_FRACTION: kvtp->type = V_TYPE_WITHBASE; break; case PERF_RAW_BASE: case PERF_PRECISION_TIMESTAMP: kvtp->type = V_TYPE_ISBASE; break; case PERF_COUNTER_COUNTER: case PERF_COUNTER_BULK_COUNT: kvtp->type = V_TYPE_WITHTIMENFREQ; break; case PERF_100NSEC_TIMER: kvtp->type = V_TYPE_WITH100NSEC; break; case PERF_100NSEC_TIMER_INV: kvtp->type = V_TYPE_WITH100NSECINV; break; default: kvtp->type = V_TYPE_SIMPLE; break; } } else { if (strcmp (kvtp->kp, "Timestamp_PerfTime") == 0) kvtp->type = V_TYPE_ISTIME; else if (strcmp (kvtp->kp, "Frequency_PerfTime") == 0) kvtp->type = V_TYPE_ISFREQ; else if (strcmp (kvtp->kp, "Timestamp_Sys100NS") == 0) kvtp->type = V_TYPE_IS100NSEC; else if (kvtp->vp[0] == 0 || isdigit (kvtp->vp[0])) kvtp->type = V_TYPE_SIMPLE; } } ::SafeArrayDestroy (props); sp->pClsObj->Release (); for (kvti = 0; kvti < kvtl; kvti++) { kvtp = &kvts[kvti]; sfsprintf (opnstr, 1024, "%s.%s.%s", objp->obj, kvtp->kp, name); if (!(opnp = (opn_t *) dtmatch (opndict, opnstr))) { sfsprintf (opnstr, 1024, "%s.%s.ALL", objp->obj, kvtp->kp); if ((opnp = (opn_t *) dtmatch (opndict, opnstr))) name = "ALL"; else sfsprintf (opnstr, 1024, "%s.%s.%s", objp->obj, kvtp->kp, name); } if (!opnp) { if (kvtp->type < V_TYPE_SUPPORT) continue; if (!(opnp = opninsert ( OPN_KIND_S, "", "", "", objp->obj, kvtp->kp, name, "" ))) { sfprintf (sfstderr, "cannot insert opn\n"); return -1; } opnp->objp = objp; } if (opnp->ep && strstr (origname, opnp->ep)) continue; if (opnp->type == 0) opnp->type = kvtp->type; opnp->vp = kvtp->vp; opnp->cv += kvtp->v; opnp->havec = TRUE; } for (kvti = 0; kvti < kvtl; kvti++) { kvtp = &kvts[kvti]; sfsprintf (opnstr, 1024, "%s.%s.SUM", objp->obj, kvtp->kp); if (!(opnp = (opn_t *) dtmatch (opndict, opnstr))) continue; if (opnp->ep && strstr (origname, opnp->ep)) continue; if (opnp->type == 0) opnp->type = kvtp->type; opnp->vp = kvtp->vp; opnp->cv += kvtp->v; opnp->havec = TRUE; } } } for ( opnp = (opn_t *) dtfirst (opndict); opnp; opnp = (opn_t *) dtnext (opndict, opnp) ) { if (opnp->kind != OPN_KIND_P || !opnp->havec) continue; if (opnp->type >= V_TYPE_SUPPORT) continue; switch (opnp->type) { case V_TYPE_STRING: #if 0 sfprintf ( sfstdout, "rt=STAT type=string name=%s str=%s%s%s%s\n", opnp->mname, opnp->vp, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); #endif break; case V_TYPE_SIMPLE: sfprintf ( sfstdout, "rt=STAT type=%s name=%s unit=%s num=%lld%s%s%s\n", opnp->mtype, opnp->mname, opnp->munit, opnp->cv, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); break; case V_TYPE_WITHBASE: sfsprintf (opnstr, 1024, "%s.%s_Base.%s", opnp->op, opnp->pp, opnp->np); if (!(opnbasep = (opn_t *) dtmatch (opndict, opnstr))) { sfprintf (sfstderr, "cannot find base property for %s\n", opnp->opn); continue; } if (!opnbasep->havec) continue; if ((v = (opnbasep->cv == 0) ? 0.00 : 100.0 * ( opnp->cv / (double) opnbasep->cv )) < 0.0) continue; sfprintf ( sfstdout, "rt=STAT type=%s name=%s unit=%s num=%lf%s%s%s\n", opnp->mtype, opnp->mname, opnp->munit, v, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); break; case V_TYPE_WITHTIMENFREQ: if (!opnp->havep) continue; sfsprintf (opnstr, 1024, "%s.Timestamp_PerfTime.%s", opnp->op, opnp->np); if (!(opntimep = (opn_t *) dtmatch (opndict, opnstr))) { sfprintf (sfstderr, "cannot find time property for %s\n", opnp->opn); continue; } if (!opntimep->havec || !opntimep->havep) continue; sfsprintf (opnstr, 1024, "%s.Frequency_PerfTime.%s", opnp->op, opnp->np); if (!(opnfreqp = (opn_t *) dtmatch (opndict, opnstr))) { sfprintf (sfstderr, "cannot find freq property for %s\n", opnp->opn); continue; } if (!opnfreqp->havec) continue; if ( opnp->cv < opnp->pv || opntimep->cv <= opntimep->pv || opnfreqp->cv == 0 ) continue; if ((v = (opnp->cv - opnp->pv) / ( (opntimep->cv - opntimep->pv) / (double) opnfreqp->cv )) < 0.0) { if (v > -1) v = 0.0; else continue; } sfprintf ( sfstdout, "rt=STAT type=%s name=%s unit=%s num=%lf%s%s%s\n", opnp->mtype, opnp->mname, opnp->munit, v, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); break; case V_TYPE_WITH100NSEC: case V_TYPE_WITH100NSECINV: if (!opnp->havep) continue; sfsprintf (opnstr, 1024, "%s.Timestamp_Sys100NS.%s", opnp->op, opnp->np); if (!(opntimep = (opn_t *) dtmatch (opndict, opnstr))) { sfprintf (sfstderr, "cannot find time property for %s\n", opnp->opn); continue; } if (!opntimep->havec || !opntimep->havep) continue; if (opnp->cv < opnp->pv || opntimep->cv <= opntimep->pv) continue; if (opnp->type == V_TYPE_WITH100NSEC) { if ((v = 100.0 * ( (opnp->cv - opnp->pv) / ((double) opntimep->cv - opntimep->pv) )) < 0.0) { if (v > -1) v = 0.0; else continue; } sfprintf ( sfstdout, "rt=STAT type=%s name=%s unit=%s num=%lf%s%s%s\n", opnp->mtype, opnp->mname, opnp->munit, v, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); } else { if ((v = 100.0 * ( 1.0 - (opnp->cv - opnp->pv) / ((double) opntimep->cv - opntimep->pv) )) < 0.0) { if (v > -1) v = 0.0; else continue; } sfprintf ( sfstdout, "rt=STAT type=%s name=%s unit=%s num=%lf%s%s%s\n", opnp->mtype, opnp->mname, opnp->munit, v, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); } break; } } return 0; }
BOOL RABIN_SelfTest(void) { BYTE t[128]; DWORD l, nDigits, pqDigits; /* p, q, n et d */ BI_DIGIT p[MAX_BI_DIGITS], q[MAX_BI_DIGITS], n[MAX_BI_DIGITS], d[MAX_BI_DIGITS]; /* buffer de travail */ BI_DIGIT w[MAX_BI_DIGITS]; printf("Validate with the reference key\n"); /* Recuperation de P, Q */ l = s2b(t, sP); BI_Decode(p, MAX_BI_DIGITS, t, l); pqDigits = BI_Digits(p, MAX_BI_DIGITS); l = s2b(t, sQ); BI_Decode(q, MAX_BI_DIGITS, t, l); /* verification que p et q passent le crible */ if (!RABIN_ValidatePrimes_BI(p, pqDigits, q, pqDigits, 2*pqDigits, 768)) { printf("Rabin failed %s %d (ValidatePrimes)\n", __FILE__, __LINE__); return FALSE; } /* Recuperation de N et D */ l = s2b(t, sN); BI_Decode(n, MAX_BI_DIGITS, t, l); nDigits = BI_Digits(n, MAX_BI_DIGITS); l = s2b(t, sD); BI_Decode(d, MAX_BI_DIGITS, t, l); /* Re-calcul de N */ BI_Mult(w, p, q, pqDigits); if (!BI_EQUAL(w, n, nDigits)) { printf("Rabin failed %s %d (calcul de N)\n", __FILE__, __LINE__); return FALSE; } /* Re-calcul de D */ RABIN_ComputePrivateKey_BI(w, MAX_BI_DIGITS, p, q, MAX_BI_DIGITS / 2); if (!BI_EQUAL(w, d, nDigits)) { printf("Rabin failed %s %d (calcul de D)\n", __FILE__, __LINE__); return FALSE; } /* Generation d'une cle */ printf("Create a new 1024 bits key\n"); nDigits = 1024/(8 * sizeof(DWORD)); if (!RABIN_GeneratePrimes_BI(p, q, nDigits, 1024)) { printf("Rabin failed %s %d (generation d'une cle)\n", __FILE__, __LINE__); return FALSE; } printf("Validate the new key\n"); if (!RABIN_ValidatePrimes_BI(p, pqDigits, q, pqDigits, nDigits, 1024)) { printf("Rabin failed %s %d (validation d'une cle)\n", __FILE__, __LINE__); return FALSE; } if (!RABIN_ComputePrivateKey_BI(w, nDigits, p, q, nDigits / 2)) { printf("Rabin failed %s %d (assemblage d'une cle)\n", __FILE__, __LINE__); return FALSE; } return TRUE; }