LL pollardRho(LL n, LL seed) { LL x, y, head = 1, tail = 2; x = y = random() % (n - 1) + 1; for ( ; ; ) { x = addMod(multiplyMod(x, x, n), seed, n); if (x == y) return n; LL d = gcd(myAbs(x - y), n); if (1 < d && d < n) return d; if (++head == tail) y = x, tail <<= 1; }} vector<LL> divisors;
/* * preop_modify - pre-operation plug-in for modify */ static int preop_modify(Slapi_PBlock *pb) { int result = LDAP_SUCCESS; Slapi_PBlock *spb = NULL; LDAPMod **checkmods = NULL; int checkmodsCapacity = 0; char *errtext = NULL; char *attrName = NULL; #ifdef DEBUG slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name, "MODIFY begin\n"); #endif BEGIN int err; char *markerObjectClass=NULL; char *requiredObjectClass=NULL; LDAPMod **mods; int modcount = 0; int ii; LDAPMod *mod; Slapi_DN *sdn = NULL; int isupdatedn; int argc; char **argv = NULL; /* * If this is a replication update, just be a noop. */ err = slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &isupdatedn); if (err) { result = uid_op_error(60); break; } if (isupdatedn) { break; } /* * Get the arguments */ result = getArguments(pb, &attrName, &markerObjectClass, &requiredObjectClass); if (UNTAGGED_PARAMETER == result) { result = LDAP_SUCCESS; /* Statically defined subtrees to monitor */ err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGC, &argc); if (err) { result = uid_op_error(53); break; } err = slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv); if (err) { result = uid_op_error(54); break; } argc--; /* First argument was attribute name */ argv++; } else if (0 != result) { break; } err = slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods); if (err) { result = uid_op_error(61); break; } /* There may be more than one mod that matches e.g. changetype: modify delete: uid uid: balster1950 - add: uid uid: scottg So, we need to first find all mods that contain the attribute which are add or replace ops and are bvalue encoded */ /* find out how many mods meet this criteria */ for(;*mods;mods++) { mod = *mods; if ((slapi_attr_type_cmp(mod->mod_type, attrName, 1) == 0) && /* mod contains target attr */ (mod->mod_op & LDAP_MOD_BVALUES) && /* mod is bval encoded (not string val) */ (mod->mod_bvalues && mod->mod_bvalues[0]) && /* mod actually contains some values */ (SLAPI_IS_MOD_ADD(mod->mod_op) || /* mod is add */ SLAPI_IS_MOD_REPLACE(mod->mod_op))) /* mod is replace */ { addMod(&checkmods, &checkmodsCapacity, &modcount, mod); } } if (modcount == 0) { break; /* no mods to check, we are done */ } /* Get the target DN */ err = slapi_pblock_get(pb, SLAPI_MODIFY_TARGET_SDN, &sdn); if (err) { result = uid_op_error(11); break; } /* * Check if it has the required object class */ if (requiredObjectClass && !(spb = dnHasObjectClass(sdn, requiredObjectClass))) { break; } /* * Passed all the requirements - this is an operation we * need to enforce uniqueness on. Now find all parent entries * with the marker object class, and do a search for each one. */ /* * stop checking at first mod that fails the check */ for (ii = 0; (result == 0) && (ii < modcount); ++ii) { mod = checkmods[ii]; if (NULL != markerObjectClass) { /* Subtree defined by location of marker object class */ result = findSubtreeAndSearch(sdn, attrName, NULL, mod->mod_bvalues, requiredObjectClass, sdn, markerObjectClass); } else { /* Subtrees listed on invocation line */ result = searchAllSubtrees(argc, argv, attrName, NULL, mod->mod_bvalues, requiredObjectClass, sdn); } } END slapi_ch_free((void **)&checkmods); freePblock(spb); if (result) { slapi_log_error(SLAPI_LOG_PLUGIN, plugin_name, "MODIFY result %d\n", result); if (result == LDAP_CONSTRAINT_VIOLATION) { errtext = slapi_ch_smprintf(moreInfo, attrName); } else { errtext = slapi_ch_strdup("Error checking for attribute uniqueness."); } slapi_send_ldap_result(pb, result, 0, errtext, 0, 0); slapi_ch_free_string(&errtext); } return (result==LDAP_SUCCESS)?0:-1; }
void SpellDiagramNode::setDiagram( int diagram ) { if( diagram >= m_spellDiagrams.size() ) return; //out of bounds m_type = diagram; Json::Value& spellDiagram = m_spellDiagrams[m_type]; Json::Value& effects = spellDiagram["effects"]; Json::Value& mods = spellDiagram["mods"]; prepareDiagram(effects.size(), mods.size()); for( int i=0; i< effects.size(); i++) { float level = effects[i]["level"].asDouble(); float x = effects[i]["x"].asDouble(); float y = effects[i]["y"].asDouble(); addEffect(i, size*x,size*y, level); } for( int i=0; i< mods.size(); i++) { float level = mods[i]["level"].asDouble(); float x = mods[i]["x"].asDouble(); float y = mods[i]["y"].asDouble(); addMod(i, size*x,size*y, level); } /* CCDrawNode* pt = NULL; switch( m_type ) { case SD_05_SERPENTS_EYE: prepareDiagram(2,4); addEffect(0, -size*0.25,0, 3); addEffect(1, size*0.25,0, 3); addMod(0, seT.x,seT.y, 3); addMod(1, seB.x,seB.y, 3); addMod(2, -size*0.5,0, 2); addMod(3, size*0.5,0, 2); break; case SD_06_LESSER_TRIQUESTRA: prepareDiagram(4,6); addEffect(0, 0,size*0.02, 3); addEffect(1, 0,size*0.25, 3); addEffect(2, -size*0.25,-size*0.1, 3); addEffect(3, size*0.25,-size*0.1, 3); addMod(0, -size*0.1667,size*0.1, 4); addMod(1, size*0.1667,size*0.1, 4); addMod(2, 0,-size*0.15, 4); addMod(3, tA.x,tA.y, 2); addMod(4, tB.x,tB.y, 2); addMod(5, tC.x,tC.y, 2); break; case SD_07_COMPASS: prepareDiagram(4,5); addEffect(0, -size*0.25, size*0.25, 3); addEffect(1, size*0.25, size*0.25, 3); addEffect(2, size*0.25,-size*0.25, 3); addEffect(3, -size*0.25,-size*0.25, 3); addMod(0, 0,0, 4); addMod(1, 0, size*0.5, 3); addMod(2, size*0.5,0, 3); addMod(3, 0,-size*0.5, 3); addMod(4, -size*0.5,0, 3); break; case SD_08_FORTRESS: prepareDiagram(1,4); addEffect(0, 0,0, 4); addMod(0, -size*0.5, size*0.5, 2); addMod(1, size*0.5, size*0.5, 2); addMod(2, size*0.5,-size*0.5, 2); addMod(3, -size*0.5,-size*0.5, 2); break; case SD_09_DRAGONS_EYE: prepareDiagram(3,4); addEffect(0, 0,0, 2); addEffect(1, -size*0.375,0, 2); addEffect(2, size*0.375,0, 2); addMod(0, seT.x,seT.y, 4); addMod(1, seB.x,seB.y, 4); addMod(2, -size*0.5,0, 2); addMod(3, size*0.5,0, 2); break; case SD_10_SEEING_EYE: prepareDiagram(3,2); addEffect(0, 0,0, 2); addEffect(1, 0, size*0.375, 2); addEffect(2, 0,-size*0.375, 2); addMod(0, -size*0.5,0, 2); addMod(1, size*0.5,0, 2); break; case SD_11_LEAF: prepareDiagram(6,7); addEffect(0, -size*0.075,size*0.02, 3); addEffect(1, -size*0.075,size*0.25, 3); addEffect(2, size*0.075,size*0.02, 3); addEffect(3, size*0.075,size*0.25, 3); addEffect(4, -size*0.25,-size*0.1, 3); addEffect(5, size*0.25,-size*0.1, 3); addMod(0, -size*0.1667,size*0.1, 4); addMod(1, size*0.1667,size*0.1, 4); addMod(2, 0,-size*0.15, 4); addMod(3, 0,size*0.15, 2); addMod(4, tA.x,tA.y, 2); addMod(5, tB.x,tB.y, 2); addMod(6, tC.x,tC.y, 2); break; case SD_12_GREATER_PYRAMID: prepareDiagram(4,3); addEffect(0, 0,0, 3); addEffect(1, -size*0.3,size*0.20, 3); addEffect(2, size*0.3,size*0.20, 3); addEffect(3, 0,-size*0.35, 3); addMod(0, tA.x,tA.y, 4); addMod(1, tB.x,tB.y, 4); addMod(2, tC.x,tC.y, 4); break; case SD_13_GREATER_TRIQUETRA: prepareDiagram(7,6); addEffect(0, 0,size*0.02, 3); addEffect(1, 0,size*0.25, 3); addEffect(2, -size*0.25,-size*0.1, 3); addEffect(3, size*0.25,-size*0.1, 3); addEffect(4, -size*0.3,size*0.20, 3); addEffect(5, size*0.3,size*0.20, 3); addEffect(6, 0,-size*0.35, 3); addMod(0, -size*0.1667,size*0.1, 4); addMod(1, size*0.1667,size*0.1, 4); addMod(2, 0,-size*0.15, 4); addMod(3, tA.x,tA.y, 4); addMod(4, tB.x,tB.y, 4); addMod(5, tC.x,tC.y, 4); break; default: prepareDiagram(0,0); } */ JsonEvent* evt = new JsonEvent("spellEditorUpdate"); evt->json = getSpellDiagramJson(); EventBus::game()->dispatch("spellEditorUpdate", evt); }
void MOD_SelectModMenu(char *basedir){ SceCtrlData pad, oldpad; sceCtrlPeekBufferPositive(0, &pad, 1); // Ch0wW: Enable the mod menu once the R trigger is hold on startup. if (!(pad.buttons & SCE_CTRL_RTRIGGER)) { // Reading current used mod char cur_mod[64]; modname = malloc(64); FILE* f; if ((f = fopen( va("%s/%s", basedir, MOD_FILE), "r")) != NULL) { char tmp[256]; fseek(f, 0, SEEK_END); int len = ftell(f); fseek(f, 0, SEEK_SET); fread(tmp, 1, len, f); fclose(f); tmp[len] = 0; sprintf(modname, "%s", tmp); } else modname = NULL; return; } // Initializing empty ModList ModsList* mods = NULL; int i = 0; int max_idx = -1; // Scanning main folder in search of mods int dd = sceIoDopen(basedir); SceIoDirent entry; int res; while (sceIoDread(dd, &entry) > 0){ if (SCE_S_ISDIR(entry.d_stat.st_mode)){ if (CheckForMod( va("%s/%s", basedir, entry.d_name))){ mods = addMod(entry.d_name, mods); max_idx++; } } } sceIoDclose(dd); // Reading current used mod char cur_mod[64]; modname = malloc(64); FILE* f; if ((f = fopen(va("%s/%s", basedir, MOD_FILE), "r")) != NULL) { char tmp[256]; fseek(f, 0, SEEK_END); int len = ftell(f); fseek(f, 0, SEEK_SET); fread(tmp, 1, len, f); fclose(f); tmp[len] = 0; sprintf(modname, "%s", tmp); sprintf(cur_mod, "Current in use mod: %s - Press START to launch vitaQuake core", tmp); }else strcpy(cur_mod,"Current in use mod: id1 - Press START to launch vitaQuake core"); // Initializing graphics stuffs vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF)); vita2d_pgf* debug_font = vita2d_load_default_pgf(); uint32_t white = RGBA8(0xFF, 0xFF, 0xFF, 0xFF); uint32_t green = RGBA8(0x00, 0xFF, 0x00, 0xFF); uint32_t red = RGBA8(0xFF, 0x00, 0x00, 0xFF); // Main loop while (max_idx >= 0){ vita2d_start_drawing(); vita2d_clear_screen(); vita2d_pgf_draw_text(debug_font, 2, 20, red, 1.0, cur_mod); // Drawing menu int y = 40; int d = 0; ModsList* ptr = mods; while (ptr != NULL && y < 540){ uint32_t color = white; if (d++ == i) color = green; vita2d_pgf_draw_text(debug_font, 2, y, color, 1.0, ptr->name); ptr = ptr->next; y += 20; } // Controls checking sceCtrlPeekBufferPositive(0, &pad, 1); if ((pad.buttons & SCE_CTRL_CROSS) && (!(oldpad.buttons & SCE_CTRL_CROSS))){ int z = 0; ModsList* tmp = mods; while (z < i){ tmp = tmp->next; z++; } sprintf(cur_mod,"Current in use mod: %s - Press START to launch vitaQuake core", tmp->name); if (!strcmp(tmp->name, "id1")) { sceIoRemove( va("%s/%s", basedir, MOD_FILE) ); modname = NULL; } else{ f = fopen(va("%s/%s", basedir, MOD_FILE), "w"); fwrite(tmp->name,1,strlen(tmp->name),f); fclose(f); strcpy(modname, tmp->name); // Refresh the mod directory. } }else if ((pad.buttons & SCE_CTRL_UP) && (!(oldpad.buttons & SCE_CTRL_UP))){ i--; if (i < 0) i = max_idx; }else if ((pad.buttons & SCE_CTRL_DOWN) && (!(oldpad.buttons & SCE_CTRL_DOWN))){ i++; if (i > max_idx) i = 0; }else if (pad.buttons & SCE_CTRL_START) break; oldpad = pad; vita2d_end_drawing(); vita2d_wait_rendering_done(); vita2d_swap_buffers(); } // Freeing stuffs ModsList* tmp = mods; ModsList* tmp2; while (tmp != NULL){ tmp2 = tmp->next; free(tmp); tmp = tmp2; } return; }