Randomly set all the variable names etc. Do not upload this project to the scratch website, as it is against the community guidelines.
(self, *, goto_origin: bool = True)
| 295 | return _monitor |
| 296 | |
| 297 | def obfuscate(self, *, goto_origin: bool = True) -> None: # noqa: C901 |
| 298 | """ |
| 299 | Randomly set all the variable names etc. Do not upload this project to the scratch website, as it is |
| 300 | against the community guidelines. |
| 301 | """ |
| 302 | # this code is an embarrassing mess. If certain features are added to sa.editor, then it could become a lot cleaner |
| 303 | chars = string.ascii_letters + string.digits + string.punctuation |
| 304 | |
| 305 | def b10_to_cbase(b10: int | float): |
| 306 | ret = "" |
| 307 | new_base = len(chars) |
| 308 | while b10 >= 1: |
| 309 | ret = chars[int(b10 % new_base)] + ret |
| 310 | b10 /= new_base |
| 311 | |
| 312 | return ret |
| 313 | |
| 314 | used = 0 |
| 315 | |
| 316 | def rand(): |
| 317 | nonlocal used |
| 318 | used += 1 |
| 319 | |
| 320 | return b10_to_cbase(used) |
| 321 | |
| 322 | for _sprite in self.sprites: |
| 323 | procedure_mappings: dict[str, str] = {} |
| 324 | argument_mappings: dict[str, str] = {} |
| 325 | done_args: list[mutation.Argument] = [] |
| 326 | |
| 327 | for _variable in _sprite.variables: |
| 328 | _variable.name = rand() |
| 329 | for _list in _sprite.lists: |
| 330 | _list.name = rand() |
| 331 | # don't rename broadcasts as these can be dynamically called |
| 332 | |
| 333 | def arg_get(name: str) -> str: |
| 334 | if name not in argument_mappings: |
| 335 | argument_mappings[name] = rand() |
| 336 | return argument_mappings[name] |
| 337 | |
| 338 | for _block in _sprite.blocks.values(): |
| 339 | if goto_origin: |
| 340 | _block.x, _block.y = 0, 0 |
| 341 | |
| 342 | # TODO: Add special handling for turbowarp debugger blocks |
| 343 | if _block.opcode in ("procedures_call", "procedures_prototype", "procedures_definition"): |
| 344 | if _block.mutation is None: |
| 345 | continue |
| 346 | |
| 347 | proccode = _block.mutation.proc_code |
| 348 | if proccode is None: |
| 349 | continue |
| 350 | |
| 351 | if proccode not in procedure_mappings: |
| 352 | parsed_ppc = _block.mutation.parsed_proc_code |
| 353 | |
| 354 | if parsed_ppc is None: |