Fork for AI-assisted matching work
Personal fork so AI-assisted decomp work has a home without disturbing upstream. README explains the fork; AGENTS.md documents the method and forbids ever opening a PR against koopthekoopa/wii-ipl. Matching progress: +9 exact functions, 0 regressions, main.dol still byte-identical (26116613f624061ba99c8d1a299aaa6efa85670d). iplESMisc gains CheckTmdParentalControl, CheckSafeDeleteTitle, NumPrivateContents, checkContentsNum and GetValidTicketIndex, plus the other functions matched in the previous pass. The load-bearing finding, written up in AGENTS.md: MWCC emits a translation unit's string literals in source-token order. A missing function, or an inverted if/else, shifts every later string offset and breaks functions that were never edited. Fixing that pool ordering lifted TMDFile::Open from 99.92 to 99.96 without touching Open. Adds tools/decomp-assist/ with pool_diff.py, ctxdiff.py, disasm_fn.py, export_pyghidra.py and the Ghidra decompilation dump.
This commit is contained in:
21
.agents/skills/typesafe-ai/LICENSE
Normal file
21
.agents/skills/typesafe-ai/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 TypeSafe AI
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
149
.agents/skills/typesafe-ai/SKILL.md
Normal file
149
.agents/skills/typesafe-ai/SKILL.md
Normal file
@@ -0,0 +1,149 @@
|
||||
---
|
||||
name: typesafe-ai
|
||||
license: MIT
|
||||
description: >
|
||||
Build AI-powered software with TypeSafe: small units of AI intelligence you
|
||||
can use like programming primitives. Its System One models, including Jev,
|
||||
turn natural language and application state into typed judgments and
|
||||
probabilities that code can combine. Use when a feature needs programmable
|
||||
common sense, when brainstorming what AI could make possible in an app, or
|
||||
when an LLM prompt-and-parse step could become a structured decision.
|
||||
Applications include routing, ranking, extraction, verification, and
|
||||
interactive experiences; these are starting points, not the limits.
|
||||
Read live docs and cookbooks to find useful patterns and discover new combinations.
|
||||
---
|
||||
|
||||
# Build with TypeSafe
|
||||
|
||||
TypeSafe makes units of AI intelligence usable like programming primitives: small
|
||||
judgments you can compose into larger capabilities. Its **System One models** return
|
||||
fast, focused judgments that software can consume directly. **Jev** is TypeSafe's
|
||||
flagship and first System One model. It understands natural language and returns
|
||||
typed answers and probabilities rather
|
||||
than generating text or reasoning explanations. Code owns the workflow; the model
|
||||
supplies programmable common sense where ordinary code needs semantic understanding.
|
||||
|
||||
## Read the live docs
|
||||
|
||||
**The live TypeSafe docs are the source of truth. Read them as part of the task.**
|
||||
This skill gives direction; the docs carry current concepts, prompting guidance,
|
||||
API contracts, SDK usage, models, limits, and worked examples.
|
||||
|
||||
- Start with the [documentation index](https://docs.typesafe.ai/llms.txt) to discover
|
||||
relevant pages and cookbooks. Use targeted reads rather than loading the entire site.
|
||||
- Mintlify serves Markdown by appending `.md` to a page path, for example
|
||||
[how to build with TypeSafe](https://docs.typesafe.ai/concepts/how-to-build-with-system-one.md).
|
||||
Follow links from the index; convert extensionless documentation page links to
|
||||
`.md` when useful. Resolve relative links against `https://docs.typesafe.ai`.
|
||||
- Before writing an integration, read the current API or chosen SDK page and the
|
||||
question guidance relevant to the design. For a new workflow, also inspect the
|
||||
closest cookbook: it often shows a better decomposition than a generic classifier.
|
||||
- If the index is unavailable, use the direct links below or the site's navigation.
|
||||
If Markdown fetching fails, try the normal page. If live access is unavailable,
|
||||
use available local docs or installed SDK types, state that limitation, and avoid
|
||||
inventing version-dependent details.
|
||||
|
||||
| Task | Start here; follow the relevant details |
|
||||
| --- | --- |
|
||||
| Understand the programming model | [System One](https://docs.typesafe.ai/concepts/system-one.md), [building guide](https://docs.typesafe.ai/concepts/how-to-build-with-system-one.md) |
|
||||
| Explore what to build | [Use-case map](https://docs.typesafe.ai/concepts/use-case-map.md), then relevant cookbooks from the index |
|
||||
| Prepare inputs and questions | [State](https://docs.typesafe.ai/concepts/state.md), [primitives](https://docs.typesafe.ai/primitives.md), then the chosen primitive's page |
|
||||
| Decide how to handle uncertainty | [Confidence](https://docs.typesafe.ai/confidence.md) |
|
||||
| Write API code | [HTTP API](https://docs.typesafe.ai/api.md), [Python SDK](https://docs.typesafe.ai/sdk/python.md), or [JavaScript SDK](https://docs.typesafe.ai/sdk/javascript.md) |
|
||||
| Update an older integration | [Migration guide](https://docs.typesafe.ai/migrating-to-v1.md) and the installed SDK's current reference |
|
||||
|
||||
## Find the useful shape
|
||||
|
||||
Start from the behavior the user wants: what will the application show, select,
|
||||
change, or hand off? Work backward to the judgments it needs. Keep known rules,
|
||||
calculations, exact lookups, and execution in code. Preserve the user's chosen stack
|
||||
and scope; add TypeSafe where semantic understanding helps.
|
||||
|
||||
When brainstorming or choosing an architecture, consider more than classification.
|
||||
The patterns below are starting points: combine primitives around the user's goal,
|
||||
including ideas that do not fit an established recipe.
|
||||
|
||||
- **Route and fill known arguments.** A request can select a handler and its typed
|
||||
parameters. Ask useful branch-specific questions up front and consume only the
|
||||
relevant answers. Explore [function calling](https://docs.typesafe.ai/cookbooks/function_calling.md)
|
||||
and [speculative fan-out](https://docs.typesafe.ai/patterns/fan-out.md).
|
||||
- **Select instead of generate.** Find candidate values or source spans in code,
|
||||
use a judgment to select the intended one, then copy or normalize it. Code can
|
||||
also assemble source text into a formatted document or reading guide. Explore
|
||||
[value extraction](https://docs.typesafe.ai/cookbooks/pre_parsed_value_extraction_cookbook.md)
|
||||
and [structure recovery](https://docs.typesafe.ai/cookbooks/autoformat.md).
|
||||
- **Find and judge evidence.** Retrieve candidates, compare their relevance to a
|
||||
query, and select useful context. Explore [reranking](https://docs.typesafe.ai/cookbooks/rerank_typesafe.md)
|
||||
and [hierarchical classification](https://docs.typesafe.ai/cookbooks/hierarchical_classification.md).
|
||||
- **Turn judgments into reusable data.** Score dimensions once, then let code or
|
||||
user controls change weights, thresholds, rankings, and views. With labeled
|
||||
outcomes, those signals can become classical ML features. Explore
|
||||
[composite scoring](https://docs.typesafe.ai/patterns/composite-scoring.md) and
|
||||
[feature discovery](https://docs.typesafe.ai/cookbooks/autoresearch_feature_discovery.md).
|
||||
- **Verify and escalate.** Check specific claims or fields against their evidence;
|
||||
send uncertain or failing cases to a person or reasoning model. Explore
|
||||
[citation checks](https://docs.typesafe.ai/cookbooks/citation_check.md) and
|
||||
[extraction cascades](https://docs.typesafe.ai/cookbooks/sde_cascade.md).
|
||||
- **Respond to changing state.** Code can retain goals and observations while fresh
|
||||
judgments guide the next bounded step. Keep inferred state distinct from observed
|
||||
facts, and check freshness before applying a result to a changed situation.
|
||||
|
||||
For open-ended requests, offer the few directions that best serve the user's goal
|
||||
and recommend a starting point. For a concrete request, choose the relevant pattern
|
||||
and build; a brainstorm is not a mandatory detour.
|
||||
|
||||
## Design the judgments
|
||||
|
||||
Choose by what the answer means, then read the relevant primitive page:
|
||||
|
||||
| Need | Primitive | Important distinction |
|
||||
| --- | --- | --- |
|
||||
| One of a defined set | [Choice](https://docs.typesafe.ai/primitives/choice.md) | Picks one option; its distribution compares competing options |
|
||||
| Whether a condition holds | [Noul](https://docs.typesafe.ai/primitives/noul.md) | Probability of yes; no separate confidence; use one per label when several may apply |
|
||||
| Degree along a described dimension | [Score](https://docs.typesafe.ai/primitives/score.md) | Probability-weighted position on ordered levels; use comparable per-item Scores for graded ranking |
|
||||
|
||||
Give each question enough relevant **state** to answer: source text, identities,
|
||||
relationships, policies, and current facts. Prefer named JSON fields when context
|
||||
has several parts. Put the judgment in **instructions** and define its possible
|
||||
answers in **criteria**. Question IDs are for code and are not sent to the model;
|
||||
include complete meaning in the question. Reference nested state with backticked
|
||||
paths such as `ticket.messages[0].text`.
|
||||
|
||||
Ask one narrow, coherent judgment per question. Split independently useful dimensions,
|
||||
without destroying the relationship being judged. A bounded action selection or
|
||||
contextual interpretation is valid; atomic does not mean literal fact extraction
|
||||
or a one-sentence limit. Strings work for simple questions. Use structured objects
|
||||
or arrays when definitions, contrasts, exclusions, or examples clarify instructions
|
||||
or criteria. Score levels must describe concrete situations and stand on their own.
|
||||
|
||||
Keep the needed answers available. Include a no-match outcome when nothing may fit;
|
||||
use a separate presence judgment when it is independently useful. For source-value
|
||||
selection, check candidate coverage: the model cannot choose an omitted value.
|
||||
|
||||
## Compose and verify
|
||||
|
||||
**Ask independent questions over the same state together**, including useful
|
||||
speculative questions. They run in parallel and cannot see one another's answers.
|
||||
State each speculative premise explicitly; code consumes the applicable answers.
|
||||
A second request is warranted when an earlier answer is needed to fetch evidence,
|
||||
construct new state, or determine the next options. Extra questions still use tokens;
|
||||
measure actual request budgets, cost, and end-to-end latency.
|
||||
|
||||
Use probabilities and confidence to guide behavior, with thresholds evaluated on
|
||||
the user's data and consequences. Choice/Score confidence summarizes distribution
|
||||
concentration, not overall workflow correctness or permission to act. A Noul near
|
||||
0.5 means similar probability for yes and no, not medium intensity. Several
|
||||
acceptable alternatives can also spread probability; low confidence need not
|
||||
invalidate a harmless preference choice. Ignore uncertainty on unused branches.
|
||||
|
||||
Keep policy explicit and raw judgments reusable. Weighted scores suit compensating
|
||||
preferences; an “any serious violation” rule needs separate conditions. Changing a
|
||||
weight or display filter need not rerun inference when evidence and question meanings
|
||||
are unchanged. Typed output guarantees the interface, not truth. System One models
|
||||
are trained for calibrated decisions; validate their performance in the target domain.
|
||||
|
||||
Test representative cases and the resulting application behavior. For failures,
|
||||
inspect the exact state, questions, candidates, answers, composition, and observed
|
||||
outcome. Separate missing evidence, model errors, code errors, and service failures.
|
||||
Treat cookbook thresholds and demo results as examples to evaluate, not universal
|
||||
rules or permanent model limitations. Keep API credentials server-side in web apps.
|
||||
1
.claude/skills/typesafe-ai
Symbolic link
1
.claude/skills/typesafe-ai
Symbolic link
@@ -0,0 +1 @@
|
||||
../../.agents/skills/typesafe-ai
|
||||
171
AGENTS.md
Normal file
171
AGENTS.md
Normal file
@@ -0,0 +1,171 @@
|
||||
# AGENTS.md
|
||||
|
||||
Guidance for AI agents working in this repository.
|
||||
|
||||
## CRITICAL RULE: never touch upstream
|
||||
|
||||
**Do not open a pull request against `koopthekoopa/wii-ipl`. Do not push to it.
|
||||
Do not open issues on it. Do not comment on it. Never. Not once.**
|
||||
|
||||
The upstream maintainers do not want AI-authored commits in their history. This
|
||||
fork exists solely so that AI-assisted matching work has somewhere to live
|
||||
without disturbing them. Breaking this rule is worse than producing no matches
|
||||
at all.
|
||||
|
||||
Concretely:
|
||||
|
||||
- `origin` is this fork, `coah80/wii-ipl`. Push here.
|
||||
- `upstream` is `koopthekoopa/wii-ipl`. Its push URL is intentionally set to
|
||||
the sentinel `DISABLED_never_push_to_upstream` so an accidental
|
||||
`git push upstream` fails instead of uploading.
|
||||
- Never run `gh pr create` with an upstream base, and never pass
|
||||
`--repo koopthekoopa/wii-ipl` to any `gh` command.
|
||||
- If a task appears to require contacting upstream, stop and ask the human.
|
||||
|
||||
If you are reading this because you are about to open a PR: don't.
|
||||
|
||||
## What this repository is
|
||||
|
||||
A matching decompilation of the Wii Menu (system menu) 4.3U. "Matching" means
|
||||
the compiled output must be byte-identical to the original binary, not merely
|
||||
functionally equivalent. Correct behaviour that compiles to different assembly
|
||||
is a failure.
|
||||
|
||||
## Build and verify
|
||||
|
||||
```
|
||||
python3 configure.py --version 43U
|
||||
ninja
|
||||
```
|
||||
|
||||
Ninja lives at `/home/cole/projects/tests/.venv/bin/ninja` in the author's
|
||||
environment.
|
||||
|
||||
The acceptance gate for any change is the DOL hash:
|
||||
|
||||
```
|
||||
build/43U/main.dol -> 26116613f624061ba99c8d1a299aaa6efa85670d
|
||||
```
|
||||
|
||||
Objects listed as `NonMatching` in `configure.py` are **not linked** into the
|
||||
DOL. Editing a `NonMatching` translation unit cannot change the DOL hash, which
|
||||
makes it safe to iterate on a partial match without breaking the build. Verify
|
||||
progress against the object file instead of the DOL:
|
||||
|
||||
```
|
||||
build/43U/src/src/<path>.o # what you just built
|
||||
build/43U/obj/src/<path>.o # the original object, ground truth
|
||||
```
|
||||
|
||||
## Tooling for measuring progress
|
||||
|
||||
`objdiff` scores each function:
|
||||
|
||||
```
|
||||
build/tools/objdiff-cli report generate -p . -o report.json -f json
|
||||
```
|
||||
|
||||
A function counts as matched only at `fuzzy_match_percent == 100.0`. Anything
|
||||
below that is not a match, regardless of how good it looks.
|
||||
|
||||
Helper tools live in `tools/decomp-assist/`:
|
||||
|
||||
- `ctxdiff.py <unit> <symbol>` — compact instruction-level diff of one function
|
||||
between your object and the original. This is the main iteration loop.
|
||||
- `disasm_fn.py <object> <symbol>` — disassembly with relocation-resolved call
|
||||
names, so you can see which real functions are being called.
|
||||
- `pool_diff.py` — diffs the string pool in `.data` between your object and the
|
||||
original, string by string. See below; this is the highest-signal tool.
|
||||
- `export_pyghidra.py` — regenerates `ghidra_decomp.txt`, decompiled C for the
|
||||
functions still missing.
|
||||
|
||||
## The single most useful finding: the string pool
|
||||
|
||||
MWCC emits a translation unit's string literals into `.data` in the order the
|
||||
compiler encounters them, and the compiler encounters them in **source-token
|
||||
order**, not runtime order. Every later string's offset therefore depends on
|
||||
every earlier one.
|
||||
|
||||
This matters enormously. If a function is missing from a translation unit, or
|
||||
references its strings in a different order than the original, then every
|
||||
string after it lands at the wrong offset, and *every function that reads those
|
||||
strings fails to match* — even functions you have not touched.
|
||||
|
||||
Observable evidence: `TMDFile::Open` sat at 99.92 percent purely because a
|
||||
string several functions earlier was 8 bytes off. Adding the correct
|
||||
`checkContentsNum` block moved it to 99.96 without touching `Open`.
|
||||
|
||||
**Always run `pool_diff.py` and fix the first divergence before tuning register
|
||||
allocation.** It points at exactly which function block is wrong or missing.
|
||||
|
||||
### Which branch you write changes the pool
|
||||
|
||||
Because emission follows source-token order, writing
|
||||
|
||||
```cpp
|
||||
if (cond) { A(); } else { B(); }
|
||||
```
|
||||
|
||||
versus
|
||||
|
||||
```cpp
|
||||
if (!cond) { B(); } else { A(); }
|
||||
```
|
||||
|
||||
emits the strings referenced by `A` and `B` in the opposite order. This is a
|
||||
free lever: if a function's codegen looks right but its strings are swapped,
|
||||
invert the condition rather than restructuring the logic. It fixed both the
|
||||
pool and the instruction stream for `GetValidTicketIndex` in one change.
|
||||
|
||||
### Missing functions must all be present
|
||||
|
||||
A string block cannot be partially correct. A function that is entirely absent
|
||||
leaves a hole, and everything downstream is shifted. Implement functions in
|
||||
**object-order** (the order their addresses appear in `config/43U/symbols.txt`
|
||||
and `splits.txt`), not in whatever order looks convenient.
|
||||
|
||||
## Workflow that produced matches
|
||||
|
||||
1. Find the next missing function in object order.
|
||||
2. Get its decompiled C from `ghidra_decomp.txt` (regenerate with
|
||||
`export_pyghidra.py` if needed).
|
||||
3. Write it as literally as possible: same order of operations, same branch
|
||||
direction, same number of temporaries.
|
||||
4. Insert it at the correct position in the source file.
|
||||
5. Build only that object: `ninja build/43U/src/src/<path>.o`.
|
||||
6. `pool_diff.py` first. Fix ordering divergences before anything else.
|
||||
7. `ctxdiff.py` next. Work through the instruction diff.
|
||||
8. Only then look at register allocation.
|
||||
|
||||
## Things that do NOT work
|
||||
|
||||
- **Frame pragmas.** `#pragma ppc_iro_level 0` fixed exactly one function out
|
||||
of roughly forty attempts and made others worse. A search across pragma
|
||||
variants produced almost no movement. Do not spend time here.
|
||||
- **Reverting to pristine upstream to unblock.** The unmodified upstream tree
|
||||
is needed as a baseline, but it does not help you match anything.
|
||||
- **Searching other forks for the missing functions.** The eleven unimplemented
|
||||
`iplESMisc` functions do not exist in any of the twenty-three public forks.
|
||||
|
||||
## Known hard cases
|
||||
|
||||
Many remaining diffs are pure compiler tie-breaks — register allocation and
|
||||
floating-point scheduling — with no source-level lever. If `ctxdiff.py` shows
|
||||
the instruction count already matches and the surviving differences are
|
||||
callee-saved register names, you are probably looking at a tie-break. Record it
|
||||
and move on rather than thrashing.
|
||||
|
||||
## Current status at the time of writing
|
||||
|
||||
- 8690 functions matched, zero regressions against the pristine baseline.
|
||||
- `main.dol` byte-identical to the original throughout.
|
||||
- `iplESMisc.cpp` is `NonMatching` and unlinked, so all work there is DOL-safe.
|
||||
- 6 functions still missing from `iplESMisc.cpp`: `DeleteEmptyTitles`,
|
||||
`DeleteDownloadTask`, `DeleteTitleContent`, `PrepareTitleDir`,
|
||||
`DeleteSavedata`, `DeleteUnauthorizedData`.
|
||||
|
||||
## Reference
|
||||
|
||||
`tools/decomp-assist/iplESMisc.reference.cpp` is a snapshot of `iplESMisc.cpp`
|
||||
with the matching work applied, kept as a reference for the string order and
|
||||
function layout that the pool depends on.
|
||||
@@ -1,3 +1,10 @@
|
||||
> **Note from this fork (coah80/wii-ipl)**
|
||||
>
|
||||
> original doesnt like ai commits, so im forking to not disturb them. :)
|
||||
>
|
||||
> This is a personal fork for AI-assisted matching work. No pull requests are
|
||||
> opened against upstream, ever. See [AGENTS.md](AGENTS.md).
|
||||
|
||||
<!--- Github Actions Badge -->
|
||||
|
||||
[Build Status]: https://github.com/koopthekoopa/wii-ipl/actions/workflows/build.yml/badge.svg
|
||||
|
||||
21
agent/skills/typesafe-ai/LICENSE
Normal file
21
agent/skills/typesafe-ai/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 TypeSafe AI
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
148
agent/skills/typesafe-ai/SKILL.md
Normal file
148
agent/skills/typesafe-ai/SKILL.md
Normal file
@@ -0,0 +1,148 @@
|
||||
---
|
||||
name: typesafe-ai
|
||||
description: >
|
||||
Build AI-powered software with TypeSafe: small units of AI intelligence you
|
||||
can use like programming primitives. Its System One models, including Jev,
|
||||
turn natural language and application state into typed judgments and
|
||||
probabilities that code can combine. Use when a feature needs programmable
|
||||
common sense, when brainstorming what AI could make possible in an app, or
|
||||
when an LLM prompt-and-parse step could become a structured decision.
|
||||
Applications include routing, ranking, extraction, verification, and
|
||||
interactive experiences; these are starting points, not the limits. Read live
|
||||
docs and cookbooks to find useful patterns and discover new combinations.
|
||||
license: MIT
|
||||
---
|
||||
# Build with TypeSafe
|
||||
|
||||
TypeSafe makes units of AI intelligence usable like programming primitives: small
|
||||
judgments you can compose into larger capabilities. Its **System One models** return
|
||||
fast, focused judgments that software can consume directly. **Jev** is TypeSafe's
|
||||
flagship and first System One model. It understands natural language and returns
|
||||
typed answers and probabilities rather
|
||||
than generating text or reasoning explanations. Code owns the workflow; the model
|
||||
supplies programmable common sense where ordinary code needs semantic understanding.
|
||||
|
||||
## Read the live docs
|
||||
|
||||
**The live TypeSafe docs are the source of truth. Read them as part of the task.**
|
||||
This skill gives direction; the docs carry current concepts, prompting guidance,
|
||||
API contracts, SDK usage, models, limits, and worked examples.
|
||||
|
||||
- Start with the [documentation index](https://docs.typesafe.ai/llms.txt) to discover
|
||||
relevant pages and cookbooks. Use targeted reads rather than loading the entire site.
|
||||
- Mintlify serves Markdown by appending `.md` to a page path, for example
|
||||
[how to build with TypeSafe](https://docs.typesafe.ai/concepts/how-to-build-with-system-one.md).
|
||||
Follow links from the index; convert extensionless documentation page links to
|
||||
`.md` when useful. Resolve relative links against `https://docs.typesafe.ai`.
|
||||
- Before writing an integration, read the current API or chosen SDK page and the
|
||||
question guidance relevant to the design. For a new workflow, also inspect the
|
||||
closest cookbook: it often shows a better decomposition than a generic classifier.
|
||||
- If the index is unavailable, use the direct links below or the site's navigation.
|
||||
If Markdown fetching fails, try the normal page. If live access is unavailable,
|
||||
use available local docs or installed SDK types, state that limitation, and avoid
|
||||
inventing version-dependent details.
|
||||
|
||||
| Task | Start here; follow the relevant details |
|
||||
| --- | --- |
|
||||
| Understand the programming model | [System One](https://docs.typesafe.ai/concepts/system-one.md), [building guide](https://docs.typesafe.ai/concepts/how-to-build-with-system-one.md) |
|
||||
| Explore what to build | [Use-case map](https://docs.typesafe.ai/concepts/use-case-map.md), then relevant cookbooks from the index |
|
||||
| Prepare inputs and questions | [State](https://docs.typesafe.ai/concepts/state.md), [primitives](https://docs.typesafe.ai/primitives.md), then the chosen primitive's page |
|
||||
| Decide how to handle uncertainty | [Confidence](https://docs.typesafe.ai/confidence.md) |
|
||||
| Write API code | [HTTP API](https://docs.typesafe.ai/api.md), [Python SDK](https://docs.typesafe.ai/sdk/python.md), or [JavaScript SDK](https://docs.typesafe.ai/sdk/javascript.md) |
|
||||
| Update an older integration | [Migration guide](https://docs.typesafe.ai/migrating-to-v1.md) and the installed SDK's current reference |
|
||||
|
||||
## Find the useful shape
|
||||
|
||||
Start from the behavior the user wants: what will the application show, select,
|
||||
change, or hand off? Work backward to the judgments it needs. Keep known rules,
|
||||
calculations, exact lookups, and execution in code. Preserve the user's chosen stack
|
||||
and scope; add TypeSafe where semantic understanding helps.
|
||||
|
||||
When brainstorming or choosing an architecture, consider more than classification.
|
||||
The patterns below are starting points: combine primitives around the user's goal,
|
||||
including ideas that do not fit an established recipe.
|
||||
|
||||
- **Route and fill known arguments.** A request can select a handler and its typed
|
||||
parameters. Ask useful branch-specific questions up front and consume only the
|
||||
relevant answers. Explore [function calling](https://docs.typesafe.ai/cookbooks/function_calling.md)
|
||||
and [speculative fan-out](https://docs.typesafe.ai/patterns/fan-out.md).
|
||||
- **Select instead of generate.** Find candidate values or source spans in code,
|
||||
use a judgment to select the intended one, then copy or normalize it. Code can
|
||||
also assemble source text into a formatted document or reading guide. Explore
|
||||
[value extraction](https://docs.typesafe.ai/cookbooks/pre_parsed_value_extraction_cookbook.md)
|
||||
and [structure recovery](https://docs.typesafe.ai/cookbooks/autoformat.md).
|
||||
- **Find and judge evidence.** Retrieve candidates, compare their relevance to a
|
||||
query, and select useful context. Explore [reranking](https://docs.typesafe.ai/cookbooks/rerank_typesafe.md)
|
||||
and [hierarchical classification](https://docs.typesafe.ai/cookbooks/hierarchical_classification.md).
|
||||
- **Turn judgments into reusable data.** Score dimensions once, then let code or
|
||||
user controls change weights, thresholds, rankings, and views. With labeled
|
||||
outcomes, those signals can become classical ML features. Explore
|
||||
[composite scoring](https://docs.typesafe.ai/patterns/composite-scoring.md) and
|
||||
[feature discovery](https://docs.typesafe.ai/cookbooks/autoresearch_feature_discovery.md).
|
||||
- **Verify and escalate.** Check specific claims or fields against their evidence;
|
||||
send uncertain or failing cases to a person or reasoning model. Explore
|
||||
[citation checks](https://docs.typesafe.ai/cookbooks/citation_check.md) and
|
||||
[extraction cascades](https://docs.typesafe.ai/cookbooks/sde_cascade.md).
|
||||
- **Respond to changing state.** Code can retain goals and observations while fresh
|
||||
judgments guide the next bounded step. Keep inferred state distinct from observed
|
||||
facts, and check freshness before applying a result to a changed situation.
|
||||
|
||||
For open-ended requests, offer the few directions that best serve the user's goal
|
||||
and recommend a starting point. For a concrete request, choose the relevant pattern
|
||||
and build; a brainstorm is not a mandatory detour.
|
||||
|
||||
## Design the judgments
|
||||
|
||||
Choose by what the answer means, then read the relevant primitive page:
|
||||
|
||||
| Need | Primitive | Important distinction |
|
||||
| --- | --- | --- |
|
||||
| One of a defined set | [Choice](https://docs.typesafe.ai/primitives/choice.md) | Picks one option; its distribution compares competing options |
|
||||
| Whether a condition holds | [Noul](https://docs.typesafe.ai/primitives/noul.md) | Probability of yes; no separate confidence; use one per label when several may apply |
|
||||
| Degree along a described dimension | [Score](https://docs.typesafe.ai/primitives/score.md) | Probability-weighted position on ordered levels; use comparable per-item Scores for graded ranking |
|
||||
|
||||
Give each question enough relevant **state** to answer: source text, identities,
|
||||
relationships, policies, and current facts. Prefer named JSON fields when context
|
||||
has several parts. Put the judgment in **instructions** and define its possible
|
||||
answers in **criteria**. Question IDs are for code and are not sent to the model;
|
||||
include complete meaning in the question. Reference nested state with backticked
|
||||
paths such as `ticket.messages[0].text`.
|
||||
|
||||
Ask one narrow, coherent judgment per question. Split independently useful dimensions,
|
||||
without destroying the relationship being judged. A bounded action selection or
|
||||
contextual interpretation is valid; atomic does not mean literal fact extraction
|
||||
or a one-sentence limit. Strings work for simple questions. Use structured objects
|
||||
or arrays when definitions, contrasts, exclusions, or examples clarify instructions
|
||||
or criteria. Score levels must describe concrete situations and stand on their own.
|
||||
|
||||
Keep the needed answers available. Include a no-match outcome when nothing may fit;
|
||||
use a separate presence judgment when it is independently useful. For source-value
|
||||
selection, check candidate coverage: the model cannot choose an omitted value.
|
||||
|
||||
## Compose and verify
|
||||
|
||||
**Ask independent questions over the same state together**, including useful
|
||||
speculative questions. They run in parallel and cannot see one another's answers.
|
||||
State each speculative premise explicitly; code consumes the applicable answers.
|
||||
A second request is warranted when an earlier answer is needed to fetch evidence,
|
||||
construct new state, or determine the next options. Extra questions still use tokens;
|
||||
measure actual request budgets, cost, and end-to-end latency.
|
||||
|
||||
Use probabilities and confidence to guide behavior, with thresholds evaluated on
|
||||
the user's data and consequences. Choice/Score confidence summarizes distribution
|
||||
concentration, not overall workflow correctness or permission to act. A Noul near
|
||||
0.5 means similar probability for yes and no, not medium intensity. Several
|
||||
acceptable alternatives can also spread probability; low confidence need not
|
||||
invalidate a harmless preference choice. Ignore uncertainty on unused branches.
|
||||
|
||||
Keep policy explicit and raw judgments reusable. Weighted scores suit compensating
|
||||
preferences; an “any serious violation” rule needs separate conditions. Changing a
|
||||
weight or display filter need not rerun inference when evidence and question meanings
|
||||
are unchanged. Typed output guarantees the interface, not truth. System One models
|
||||
are trained for calibrated decisions; validate their performance in the target domain.
|
||||
|
||||
Test representative cases and the resulting application behavior. For failures,
|
||||
inspect the exact state, questions, candidates, answers, composition, and observed
|
||||
outcome. Separate missing evidence, model errors, code errors, and service failures.
|
||||
Treat cookbook thresholds and demo results as examples to evaluate, not universal
|
||||
rules or permanent model limitations. Keep API credentials server-side in web apps.
|
||||
@@ -60,10 +60,7 @@ namespace ipl {
|
||||
y = fy;
|
||||
}
|
||||
|
||||
void operator=(const VEC2& r) {
|
||||
x = r.x;
|
||||
y = r.y;
|
||||
}
|
||||
void operator=(const VEC2& r);
|
||||
|
||||
VEC2 operator*(f32 val) const { return VEC2(x * val, y * val); }
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace ipl {
|
||||
Interface* getYoungController();
|
||||
|
||||
private:
|
||||
// u8 dummy[0x2F8];
|
||||
u8 dummy[0x2F8];
|
||||
};
|
||||
} // namespace controller
|
||||
} // namespace ipl
|
||||
|
||||
@@ -57,6 +57,8 @@ namespace ipl {
|
||||
|
||||
static BOOL __IsPCEnable();
|
||||
|
||||
static ESError NumPrivateContents(EGG::Heap* heap, ESTitleId titleId);
|
||||
|
||||
static BOOL ChangeUid(ESTitleId titleId);
|
||||
|
||||
static u32 NumInodesSaveDirRoot(ESTitleId titleId);
|
||||
|
||||
@@ -53,7 +53,10 @@ namespace ipl {
|
||||
|
||||
static void setOrthoTrans(const math::VEC3& translate) { mArg.mOrthoTrans = translate; }
|
||||
|
||||
static void setOrthoScale(const math::VEC2& scale) NO_INLINE { mArg.mOrthoScale = scale; }
|
||||
static void setOrthoScale(const math::VEC2& scale) NO_INLINE {
|
||||
mArg.mOrthoScale.x = scale.x;
|
||||
mArg.mOrthoScale.y = scale.y;
|
||||
}
|
||||
|
||||
private:
|
||||
static Arg mArg;
|
||||
|
||||
11
skills-lock.json
Normal file
11
skills-lock.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": 1,
|
||||
"skills": {
|
||||
"typesafe-ai": {
|
||||
"source": "typesafe-ai/skills",
|
||||
"sourceType": "github",
|
||||
"skillPath": "skills/typesafe-ai/SKILL.md",
|
||||
"computedHash": "9cd84c5e535dec8dec59917c110f9c00b4a61faadb86b432ec7e41051170af12"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1981,6 +1981,8 @@ namespace ipl {
|
||||
}
|
||||
}
|
||||
|
||||
#pragma push
|
||||
#pragma ppc_iro_level 0
|
||||
BoardObject* Board::get_log_obj() {
|
||||
BoardObject* logObj = NULL;
|
||||
|
||||
@@ -1994,6 +1996,7 @@ namespace ipl {
|
||||
|
||||
return logObj;
|
||||
}
|
||||
#pragma pop
|
||||
|
||||
Board::ObjList::ObjList() : mObjects() {
|
||||
nw4r::ut::List_Init(&mUsedObjs, offsetof(BoardObject, mLinkNode));
|
||||
|
||||
@@ -2511,8 +2511,9 @@ namespace ipl {
|
||||
} else {
|
||||
if (System::getLanguage() == SC_LANG_ENGLISH) {
|
||||
swprintf(limitStr, 65, L"%ls %d%ls%02d", limitStr, hour, System::getMessage(MESG_CHAN_SEL_SEPERATOR_2), minute);
|
||||
} else if (System::getLanguage() == SC_LANG_JAPANESE || System::getLanguage() == SC_LANG_KOREAN ||
|
||||
System::getLanguage() == SC_LANG_GERMAN) {
|
||||
} else {
|
||||
if (System::getLanguage() == SC_LANG_JAPANESE || System::getLanguage() == SC_LANG_KOREAN ||
|
||||
System::getLanguage() == SC_LANG_GERMAN) {
|
||||
if (hour == 1) {
|
||||
swprintf(local_38, 16, L"1%ls", System::getMessage(MESG_CHAN_SEL_SEPERATOR));
|
||||
} else if (hour != 0) {
|
||||
@@ -2548,10 +2549,10 @@ namespace ipl {
|
||||
} else if (minute != 0) {
|
||||
swprintf(local_58, 16, L"%02d%ls", minute, System::getMessage(MESG_CHAN_SEL_NO_SEPERATOR_2));
|
||||
}
|
||||
}
|
||||
swprintf(limitStr, 65, L"%ls %ls%ls", limitStr, local_38, local_58);
|
||||
}
|
||||
}
|
||||
|
||||
swprintf(limitStr, 65, L"%ls %ls%ls", limitStr, local_38, local_58);
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelTitle::getTmdTask(void* work) {
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace ipl {
|
||||
mbClosing = false;
|
||||
unk_0x7D = true;
|
||||
mNwc24ErrCountdown = 0;
|
||||
mpCaptionString = 0;
|
||||
mbToFriend = false;
|
||||
|
||||
mpCaptionAllocator = new EGG::Allocator(getSceneHeap(), 4);
|
||||
|
||||
@@ -82,7 +82,6 @@ namespace ipl {
|
||||
mNwc24ErrCountdown2 = 0;
|
||||
|
||||
// Text balloon for Mii face
|
||||
// What the fuck is up with these two floats
|
||||
mpNigaoeBalloon =
|
||||
new TextBalloon(getSceneHeap(), mpBalloonFile, "arc", "my_IplTopBalloon_a.brlyt", math::VEC3(0.0f, 0.0f, 0.0f), 120.0f, 30.0f);
|
||||
|
||||
|
||||
@@ -14,8 +14,14 @@
|
||||
const f32 lbl_8160D2C0[] = {0.2, 0.3, 0, 0};
|
||||
|
||||
namespace ipl {
|
||||
namespace controller {
|
||||
namespace math {
|
||||
void VEC2::operator=(const VEC2& r) {
|
||||
x = r.x;
|
||||
y = r.y;
|
||||
}
|
||||
}
|
||||
|
||||
namespace controller {
|
||||
void Base::read() {
|
||||
if (isValidBtn()) {
|
||||
if (downTrg(BTN_INTERACT)) {
|
||||
@@ -296,24 +302,24 @@ namespace ipl {
|
||||
math::VEC2 ret;
|
||||
if (Revolution::isValidDpd()) {
|
||||
ret.set(unk_0x20->horizon.x, unk_0x20->horizon.y);
|
||||
return ret;
|
||||
} else {
|
||||
return math::VEC2(1.0f, -0.2679492f);
|
||||
ret.x = 1.0f;
|
||||
ret.y = -0.2679492f;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
math::VEC2 Classic::getDpdPos() const {
|
||||
math::VEC2 ret;
|
||||
if (Revolution::isValidDpd()) {
|
||||
ret.set(unk_0x20->pos.x, unk_0x20->pos.y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (unk_0x2C != 0) {
|
||||
} else if (unk_0x2C != 0) {
|
||||
ret = unk_0x24;
|
||||
return ret;
|
||||
} else {
|
||||
ret.x = 1.0f / 0.0f;
|
||||
ret.y = 1.0f / 0.0f;
|
||||
}
|
||||
return math::VEC2(1.0f / 0.0f, 1.0f / 0.0f);
|
||||
return ret;
|
||||
}
|
||||
} // namespace controller
|
||||
} // namespace ipl
|
||||
|
||||
@@ -540,14 +540,15 @@ namespace ipl {
|
||||
}
|
||||
|
||||
int Manager::getAvailableInList(const ESTitleId* titleIds, u32 titleCount) {
|
||||
int i;
|
||||
int count = 0;
|
||||
for (int i = 0; i < titleCount; i++) {
|
||||
if (titleIds[i]) {
|
||||
if (mData.chanInfo[count / MAX_CHANNEL_INDEX][count % MAX_CHANNEL_INDEX].primaryType != channel::PRIMARY_TYPE_CHANNEL) {
|
||||
for (i = 0; i < titleCount; i++) {
|
||||
if (!titleIds[i]) {
|
||||
if (mData.chanInfo[count / MAX_CHANNEL_INDEX][count % MAX_CHANNEL_INDEX].primaryType != channel::PRIMARY_TYPE_DISK) {
|
||||
return count;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -590,10 +591,11 @@ namespace ipl {
|
||||
}
|
||||
case 3: {
|
||||
switch ((u16)oldVersion) {
|
||||
case 2: {
|
||||
case 0:
|
||||
case 1: {
|
||||
setDefaultKeyboard();
|
||||
}
|
||||
case 3: {
|
||||
case 2: {
|
||||
setDefaultSDMenu();
|
||||
}
|
||||
default: {
|
||||
|
||||
@@ -1219,7 +1219,7 @@ namespace ipl {
|
||||
}
|
||||
|
||||
u32 System::getLanguage() {
|
||||
u32 lang = SCGetLanguage();
|
||||
s32 lang = SCGetLanguage();
|
||||
s32 region = getRegion();
|
||||
|
||||
switch (region) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "utility/iplESMisc.h"
|
||||
#include "BS2/BS2.h"
|
||||
|
||||
#include "system/iplSystem.h"
|
||||
#include "system/iplErrorHandler.h"
|
||||
|
||||
#include <private/es.h>
|
||||
|
||||
#include <revolution/sc.h>
|
||||
@@ -189,6 +192,173 @@ namespace ipl {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ESError ESMisc::checkContentsNum(ESTitleId titleId, ESTmdView* tmdView) {
|
||||
s32 result = 0;
|
||||
u32 numContents = 0;
|
||||
ESContentId contentIds[ES_MAX_CONTENT] ALIGN32;
|
||||
|
||||
s32 privateCount = PrivateContentsExist(titleId);
|
||||
|
||||
if (privateCount == 0) {
|
||||
OSReport("ESMisc::checkContentsNum: no TMD or content for 0x%016llx.\n", titleId);
|
||||
return 1;
|
||||
} else {
|
||||
u16 num = tmdView->head.numContents;
|
||||
u32 i;
|
||||
s32 count = 0;
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
if ((tmdView->contents[i].type & 0x8000) == 0) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (privateCount == count) {
|
||||
result = 0;
|
||||
} else {
|
||||
ESError err = ES_ListTitleContentsOnCard(titleId, NULL, &numContents);
|
||||
result = err;
|
||||
|
||||
if (err != ES_ERR_OK) {
|
||||
OSReport("ESMisc::checkContentsNum: ES_ListTitleContentsOnCard err %d\n", err);
|
||||
} else if (numContents == 0) {
|
||||
OSReport("ESMisc::checkContentsNum: no content for 0x%016llx.\n", titleId);
|
||||
result = 1;
|
||||
} else {
|
||||
err = ES_ListTitleContentsOnCard(titleId, contentIds, &numContents);
|
||||
result = err;
|
||||
|
||||
if (err == ES_ERR_OK) {
|
||||
bool found = false;
|
||||
|
||||
for (i = 0; i < numContents && !found; i++) {
|
||||
for (u32 j = 0; j < num; j++) {
|
||||
if (contentIds[i] == tmdView->contents[j].cid && (tmdView->contents[j].type & 0x8000) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
OSReport("ESMisc::checkContentsNum: 0x%016llx is already deleted.\n", titleId);
|
||||
result = 1;
|
||||
} else {
|
||||
for (u32 j = 0; j < num; j++) {
|
||||
u32 k = 0;
|
||||
for (i = 0; i < numContents; i++) {
|
||||
if (contentIds[i] == tmdView->contents[j].cid) {
|
||||
break;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
if (k == numContents && (tmdView->contents[j].type & 0x4000) == 0) {
|
||||
OSReport("ESMisc::checkContentsNum: not complete: non-optional cidx %d missing for 0x%016llx.\n",
|
||||
tmdView->contents[j].index, titleId);
|
||||
result = 2;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
OSReport("ESMisc::checkContentsNum: complete: only missing non-optional contents for 0x%016llx.\n", titleId);
|
||||
result = 0;
|
||||
}
|
||||
} else {
|
||||
OSReport("ESMisc::checkContentsNum: ES_ListTitleContentsOnCard failed.[%d]\n", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
return result;
|
||||
}
|
||||
|
||||
ESError ESMisc::GetValidTicketIndex(EGG::Heap* heap, ESTitleId titleId, ESTicketView* ticket, u32 ticketLength) {
|
||||
bool allocated = false;
|
||||
bool found = false;
|
||||
ESTicketView* ticketView;
|
||||
s32 index;
|
||||
|
||||
if (ticket == NULL) {
|
||||
if (GetTicketViewList(heap, titleId, &ticket, &ticketLength) < 0) {
|
||||
if (ticket != NULL) {
|
||||
heap->free(ticket);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
allocated = true;
|
||||
}
|
||||
|
||||
ticketView = (ESTicketView*)heap->alloc(0xe0, -32);
|
||||
|
||||
if (ESP_InitLib() < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
index = __OSGetValidTicketIndex(ticket, ticketLength);
|
||||
|
||||
if (index < -1) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (index == -1) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
memcpy(ticketView, (u8*)ticket + index * 0xd8, 0xd8);
|
||||
|
||||
{
|
||||
ESFd fd = ES_OpenTitleContentFile(titleId, ticketView, 0);
|
||||
|
||||
if (fd < 0) {
|
||||
OSReport("ESMisc::GetValidTicketIndex: ES_OpenTitleContentFile fd %d\n", fd);
|
||||
} else {
|
||||
u8* buf = (u8*)heap->alloc(0x40, 32);
|
||||
s32 numRead = ES_ReadContentFile(fd, buf, 0x40);
|
||||
|
||||
if (numRead != 0x40) {
|
||||
OSReport("ESMisc::GetValidTicketIndex: ES_ReadContentFile err %d\n", numRead);
|
||||
heap->free(buf);
|
||||
|
||||
if (ES_CloseContentFile(fd) < 0) {
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
if (ES_CloseContentFile(fd) < 0) {
|
||||
heap->free(buf);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (buf[0] == 0) {
|
||||
OSReport("ESMisc::GetValidTicketIndex: No name\n");
|
||||
heap->free(buf);
|
||||
} else {
|
||||
heap->free(buf);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
heap->free(ticketView);
|
||||
|
||||
if (allocated && ticket != NULL) {
|
||||
heap->free(ticket);
|
||||
}
|
||||
|
||||
return found ? index : -1;
|
||||
|
||||
error:
|
||||
heap->free(ticketView);
|
||||
|
||||
if (allocated && ticket != NULL) {
|
||||
heap->free(ticket);
|
||||
}
|
||||
|
||||
System::getErrorHandler()->set(ErrorHandler::DEFAULT, MESG_ERR_FILE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// DeleteSharedContent did not survive
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: MEMAllocate for TMD err\n");
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: ES_ListSharedContents1 err %d\n");
|
||||
@@ -258,6 +428,101 @@ namespace ipl {
|
||||
}
|
||||
}
|
||||
|
||||
u32 ESMisc::CheckTmdParentalControl(ESTmdView* tmdView) {
|
||||
if (!__IsPCEnable()) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
u8 ratings[16];
|
||||
memcpy(ratings, tmdView->head.reserved.ratings, 16);
|
||||
|
||||
SCParentalControlsInfo pcInfo;
|
||||
if (!SCGetParentalControl(&pcInfo)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (pcInfo.enable & SC_PARENTAL_FLAG_ENABLED) {
|
||||
u8 rating = ratings[pcInfo.org];
|
||||
|
||||
if (rating & SC_PARENTAL_FLAG_ENABLED) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (rating & 0x40) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((rating & SC_PARENTAL_RATING_ENABLED) > pcInfo.rating) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ESError ESMisc::NumPrivateContents(EGG::Heap* heap, ESTitleId titleId) {
|
||||
ESTmdView* tmdView = NULL;
|
||||
ESContentId* contentIds = NULL;
|
||||
u32 numContents;
|
||||
u32 tmdViewSize;
|
||||
|
||||
ESError ret = ES_GetTmdView(titleId, NULL, &tmdViewSize);
|
||||
if (ret == ES_ERR_DONT_EXISTS) {
|
||||
return ES_ERR_OK;
|
||||
}
|
||||
|
||||
if (ret < ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_GetTmdView1 failed: %d", ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = ES_ListTitleContentsOnCard(titleId, NULL, &numContents);
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_ListTitleContentsOnCard1 failed: %d for %016llx", ret, titleId);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (numContents == 0) {
|
||||
return ES_ERR_OK;
|
||||
}
|
||||
|
||||
tmdView = (ESTmdView*)heap->alloc(OSRoundUp32B(tmdViewSize), -DEFAULT_ALIGN);
|
||||
contentIds = (ESContentId*)heap->alloc(OSRoundUp32B(numContents * sizeof(ESContentId)), -DEFAULT_ALIGN);
|
||||
|
||||
ret = ES_ListTitleContentsOnCard(titleId, contentIds, &numContents);
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_ListTitleContentsOnCard2 failed: %d for %016llx", ret, titleId);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = ES_GetTmdView(titleId, tmdView, &tmdViewSize);
|
||||
if (ret < ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_GetTmdView2 failed: %d", ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
u32 j = 0;
|
||||
for (u32 i = 0; i < tmdView->head.numContents && j < numContents; i++) {
|
||||
if (tmdView->contents[i].cid == contentIds[j]) {
|
||||
if (!(tmdView->contents[i].type & 0x8000)) {
|
||||
ret++;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (contentIds != NULL) {
|
||||
heap->free(contentIds);
|
||||
}
|
||||
if (tmdView != NULL) {
|
||||
heap->free(tmdView);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL ESMisc::ChangeUid(ESTitleId titleId) {
|
||||
s32 ret = ES_SetUid(titleId);
|
||||
if (ret != ES_ERR_OK) {
|
||||
@@ -300,6 +565,57 @@ namespace ipl {
|
||||
return result;
|
||||
}
|
||||
|
||||
s32 ESMisc::CheckSafeDeleteTitle(EGG::Heap* heap, ESTitleId titleId) {
|
||||
s32 result;
|
||||
ESTmdView* tmdView = NULL;
|
||||
u32 tmdViewSize;
|
||||
|
||||
if (PrivateContentsExist(titleId) != 0) {
|
||||
ES_ERR_REPORT("%016llx is not empry", titleId);
|
||||
result = 0;
|
||||
} else {
|
||||
result = NumPrivateContents(heap, titleId);
|
||||
|
||||
if (result < 0) {
|
||||
ES_ERR_REPORT("NumPrivateContents failed: %d", result);
|
||||
} else if (result > 0) {
|
||||
result = 0;
|
||||
} else {
|
||||
ESError err = ES_GetTmdView(titleId, NULL, &tmdViewSize);
|
||||
result = err;
|
||||
|
||||
if (err == ES_ERR_DONT_EXISTS) {
|
||||
result = ES_ERR_OK;
|
||||
} else if (err != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_GetTmdView1 failed: %d", err);
|
||||
} else {
|
||||
tmdView = (ESTmdView*)heap->alloc(OSRoundUp32B(tmdViewSize), -DEFAULT_ALIGN);
|
||||
result = ES_GetTmdView(titleId, tmdView, &tmdViewSize);
|
||||
|
||||
if (result != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_GetTmdView2 failed: %d", result);
|
||||
} else if ((tmdView->head.titleVersion >> 8) != 0) {
|
||||
result = 0;
|
||||
} else {
|
||||
result = NumInodesSaveDirRoot(titleId);
|
||||
|
||||
if (result < 0) {
|
||||
ES_ERR_REPORT("NumInodesSaveDirRoot failed: %d", result);
|
||||
} else {
|
||||
result = (result == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tmdView != NULL) {
|
||||
heap->free(tmdView);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
s32 ESMisc::DeleteTitle(EGG::Heap* heap, ESTitleId titleId) {
|
||||
TMDFile tmdFile(heap);
|
||||
|
||||
@@ -354,21 +670,21 @@ namespace ipl {
|
||||
if (ret == NAND_RESULT_NOEXISTS) {
|
||||
ret = NANDPrivateCreate(fileName, NAND_PERM_ALL_RW, 0);
|
||||
if (ret != NAND_RESULT_OK) {
|
||||
ES_ERR_REPORT("NANDCreate %s err %d", fileName, ret);
|
||||
ES_ERR_REPORT("NANDCreate %s err: %d", fileName, ret);
|
||||
return ret;
|
||||
}
|
||||
ret = NANDPrivateOpen(fileName, &mFile, NAND_ACCESS_RW);
|
||||
}
|
||||
|
||||
if (ret != NAND_RESULT_OK) {
|
||||
ES_ERR_REPORT("NANDOpen %s err %d", fileName, ret);
|
||||
ES_ERR_REPORT("NANDOpen %s err: %d", fileName, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
mbFileOpen = TRUE;
|
||||
ret = NANDGetLength(&mFile, &mFileLength);
|
||||
if (ret != NAND_RESULT_OK) {
|
||||
ES_ERR_REPORT("NANDGetLength %s err %d", fileName, ret);
|
||||
ES_ERR_REPORT("NANDGetLength %s err: %d", fileName, ret);
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
|
||||
41
tools/decomp-assist/ctxdiff.py
Normal file
41
tools/decomp-assist/ctxdiff.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compact function diff with context: python ctxdiff.py <unit> <symbol> [--full]"""
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, "/home/cole/projects/tests")
|
||||
from odiff import dis, sym
|
||||
import os
|
||||
import itertools
|
||||
|
||||
os.chdir("/home/cole/projects/tests/wii-ipl")
|
||||
|
||||
|
||||
def main():
|
||||
unit, name = sys.argv[1], sys.argv[2]
|
||||
so, ss = sym(f"build/43U/src/{unit}.o", name)
|
||||
bo, bs = sym(f"build/43U/obj/{unit}.o", name)
|
||||
a = dis(f"build/43U/src/{unit}.o", so, ss)
|
||||
b = dis(f"build/43U/obj/{unit}.o", bo, bs)
|
||||
print(f"src {hex(ss)} base {hex(bs)} insns {len(a)}/{len(b)}")
|
||||
if len(a) != len(b):
|
||||
import difflib
|
||||
sm = difflib.SequenceMatcher(None, [str(x) for x in a], [str(x) for x in b], autojunk=False)
|
||||
for tag, i1, i2, j1, j2 in sm.get_opcodes():
|
||||
if tag == 'equal':
|
||||
continue
|
||||
print(f"--- {tag} mine {i1}:{i2} base {j1}:{j2}")
|
||||
for k in range(i1, i2):
|
||||
print(f" M {k:>4} {a[k][0]} {a[k][1]}")
|
||||
for k in range(j1, j2):
|
||||
print(f" B {k:>4} {b[k][0]} {b[k][1]}")
|
||||
return
|
||||
diffs = [i for i, (x, y) in enumerate(zip(a, b)) if x != y]
|
||||
print(f"diffs {len(diffs)}: {diffs[:20]}")
|
||||
for i, (x, y) in enumerate(zip(a, b)):
|
||||
if x != y:
|
||||
print(f" {i:>4} M {x[0]} {x[1]}")
|
||||
print(f" B {y[0]} {y[1]}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
37
tools/decomp-assist/disasm_fn.py
Normal file
37
tools/decomp-assist/disasm_fn.py
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Disassemble a function from an object file with relocations resolved.
|
||||
|
||||
Usage: disasm_fn.py <objectfile> <symbol>
|
||||
"""
|
||||
import sys
|
||||
|
||||
from capstone import CS_ARCH_PPC, CS_MODE_32, CS_MODE_BIG_ENDIAN, Cs
|
||||
from elftools.elf.elffile import ELFFile
|
||||
|
||||
|
||||
def main():
|
||||
path, name = sys.argv[1], sys.argv[2]
|
||||
with open(path, "rb") as f:
|
||||
e = ELFFile(f)
|
||||
st = e.get_section_by_name(".symtab")
|
||||
syms = list(st.iter_symbols())
|
||||
names = [s.name for s in syms]
|
||||
target = next(s for s in syms if s.name == name)
|
||||
off, size = target["st_value"], target["st_size"]
|
||||
relocs = {}
|
||||
rt = e.get_section_by_name(".rela.text")
|
||||
for r in rt.iter_relocations():
|
||||
relocs[r["r_offset"]] = names[r["r_info_sym"]]
|
||||
data = e.get_section_by_name(".text").data()[off:off + size]
|
||||
md = Cs(CS_ARCH_PPC, CS_MODE_32 + CS_MODE_BIG_ENDIAN)
|
||||
md.detail = True
|
||||
print(f"{name} size {hex(size)} ({size // 4} insns)")
|
||||
for i in md.disasm(data, off):
|
||||
note = ""
|
||||
if i.address in relocs:
|
||||
note = " ; " + relocs[i.address]
|
||||
print(f"{hex(i.address)} {i.mnemonic:<8} {i.op_str}{note}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
37
tools/decomp-assist/export_pyghidra.py
Normal file
37
tools/decomp-assist/export_pyghidra.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import os
|
||||
os.environ.setdefault("GHIDRA_INSTALL_DIR", "/tmp/opencode/ghidra_12.1.3_PUBLIC")
|
||||
os.environ.setdefault("JAVA_HOME", "/tmp/opencode/jdk")
|
||||
import pyghidra
|
||||
|
||||
pyghidra.start()
|
||||
from java.io import File
|
||||
from ghidra.base.project import GhidraProject
|
||||
from ghidra.app.decompiler import DecompInterface
|
||||
from ghidra.util.task import ConsoleTaskMonitor
|
||||
|
||||
proj = GhidraProject.openProject("/tmp/opencode/gproj", "wii", True)
|
||||
prog = proj.openProgram("/", "ipl.bin", True)
|
||||
iface = DecompInterface()
|
||||
iface.openProgram(prog)
|
||||
mon = ConsoleTaskMonitor()
|
||||
|
||||
addrs = [0x81365C40, 0x81365EDC, 0x81366A2C, 0x81366C7C, 0x81366EE4, 0x813670A0, 0x813671C4, 0x813673E0]
|
||||
out = open("/tmp/opencode/ghidra_decomp.txt", "w")
|
||||
for a in addrs:
|
||||
addr = prog.getAddressFactory().getDefaultAddressSpace().getAddress(a)
|
||||
fn = prog.getFunctionManager().getFunctionAt(addr)
|
||||
if fn is None:
|
||||
fn = prog.getFunctionManager().getFunctionContaining(addr)
|
||||
if fn is None:
|
||||
out.write("=== %x NOT FOUND\n\n" % a)
|
||||
continue
|
||||
res = iface.decompileFunction(fn, 120, mon)
|
||||
out.write("=== %s @ %x\n" % (fn.getName(), a))
|
||||
if res and res.decompileCompleted():
|
||||
out.write(res.getDecompiledFunction().getC())
|
||||
else:
|
||||
out.write("DECOMP FAILED: %s\n" % (res.getErrorMessage() if res else "?"))
|
||||
out.write("\n\n")
|
||||
out.close()
|
||||
print("EXPORT DONE")
|
||||
proj.close()
|
||||
746
tools/decomp-assist/ghidra_decomp.txt
Normal file
746
tools/decomp-assist/ghidra_decomp.txt
Normal file
@@ -0,0 +1,746 @@
|
||||
=== FUN_81365c40 @ 81365c40
|
||||
|
||||
void FUN_81365c40(undefined4 param_1,undefined4 param_2,int param_3)
|
||||
|
||||
{
|
||||
ushort uVar1;
|
||||
undefined4 uVar2;
|
||||
undefined4 uVar3;
|
||||
int iVar4;
|
||||
int iVar5;
|
||||
bool bVar7;
|
||||
uint uVar6;
|
||||
int iVar8;
|
||||
uint uVar9;
|
||||
uint uVar10;
|
||||
undefined8 uVar11;
|
||||
uint auStack_840 [8];
|
||||
int aiStack_820 [520];
|
||||
|
||||
uVar11 = FUN_815f94bc();
|
||||
uVar2 = (undefined4)((ulonglong)uVar11 >> 0x20);
|
||||
uVar3 = (undefined4)uVar11;
|
||||
iVar8 = 0;
|
||||
auStack_840[0] = 0;
|
||||
uVar11 = FUN_81365a08();
|
||||
iVar4 = (int)((ulonglong)uVar11 >> 0x20);
|
||||
if (iVar4 == 0) {
|
||||
FUN_8152e6a0(s_ESMisc__checkContentsNum__no_TMD_8164145e,(int)uVar11,uVar2,uVar3);
|
||||
iVar8 = 1;
|
||||
}
|
||||
else {
|
||||
uVar1 = *(ushort *)(param_3 + 0x5a);
|
||||
iVar5 = 0;
|
||||
for (uVar9 = (uint)uVar1; uVar9 != 0; uVar9 = uVar9 - 1) {
|
||||
if ((*(ushort *)(param_3 + iVar8 + 0x62) & 0x8000) == 0) {
|
||||
iVar5 = iVar5 + 1;
|
||||
}
|
||||
iVar8 = iVar8 + 0x10;
|
||||
}
|
||||
if (iVar4 == iVar5) {
|
||||
iVar8 = 0;
|
||||
}
|
||||
else {
|
||||
uVar11 = FUN_815be5d8(uVar2,uVar3,0,auStack_840);
|
||||
iVar8 = (int)((ulonglong)uVar11 >> 0x20);
|
||||
if (iVar8 == 0) {
|
||||
if (auStack_840[0] == 0) {
|
||||
FUN_8152e6a0(s_ESMisc__checkContentsNum__no_con_816414d7,(int)uVar11,uVar2,uVar3);
|
||||
iVar8 = 1;
|
||||
}
|
||||
else {
|
||||
uVar11 = FUN_815be5d8(uVar2,uVar3,aiStack_820,auStack_840);
|
||||
iVar8 = (int)((ulonglong)uVar11 >> 0x20);
|
||||
iVar4 = (int)uVar11;
|
||||
if (iVar8 == 0) {
|
||||
bVar7 = false;
|
||||
uVar9 = 0;
|
||||
iVar8 = 0;
|
||||
while ((uVar9 < auStack_840[0] && (!bVar7))) {
|
||||
iVar4 = 0;
|
||||
for (uVar6 = 0; uVar6 < *(ushort *)(param_3 + 0x5a); uVar6 = uVar6 + 1) {
|
||||
if ((*(int *)((int)aiStack_820 + iVar8) == *(int *)(param_3 + iVar4 + 0x5c)) &&
|
||||
((*(ushort *)(param_3 + iVar4 + 0x62) & 0x8000) == 0)) {
|
||||
bVar7 = true;
|
||||
break;
|
||||
}
|
||||
iVar4 = iVar4 + 0x10;
|
||||
}
|
||||
uVar9 = uVar9 + 1;
|
||||
iVar8 = iVar8 + 4;
|
||||
}
|
||||
if (bVar7) {
|
||||
iVar8 = 0;
|
||||
for (uVar9 = 0; uVar9 < uVar1; uVar9 = uVar9 + 1) {
|
||||
uVar6 = 0;
|
||||
uVar10 = auStack_840[0];
|
||||
for (iVar4 = 0;
|
||||
(uVar10 != 0 &&
|
||||
(*(int *)((int)aiStack_820 + iVar4) != *(int *)(param_3 + iVar8 + 0x5c)));
|
||||
iVar4 = iVar4 + 4) {
|
||||
uVar6 = uVar6 + 1;
|
||||
uVar10 = uVar10 - 1;
|
||||
}
|
||||
if ((uVar6 == auStack_840[0]) &&
|
||||
(iVar4 = param_3 + iVar8, (*(ushort *)(iVar4 + 0x62) & 0x4000) == 0)) {
|
||||
FUN_8152e6a0(s_ESMisc__checkContentsNum__not_co_81641545,
|
||||
*(undefined2 *)(iVar4 + 0x60),uVar2,uVar3);
|
||||
iVar8 = 2;
|
||||
goto LAB_81365ec0;
|
||||
}
|
||||
iVar8 = iVar8 + 0x10;
|
||||
}
|
||||
FUN_8152e6a0(s_ESMisc__checkContentsNum__comple_8164159a,iVar4,uVar2,uVar3);
|
||||
iVar8 = 0;
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s_ESMisc__checkContentsNum__0x_016_8164150c,iVar4,uVar2,uVar3);
|
||||
iVar8 = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s_ESMisc__checkContentsNum__ES_Lis_816415f1,iVar8);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s_ESMisc__checkContentsNum__ES_Lis_8164149a,iVar8);
|
||||
}
|
||||
}
|
||||
}
|
||||
LAB_81365ec0:
|
||||
FUN_815f9508(iVar8);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
=== FUN_81365edc @ 81365edc
|
||||
|
||||
/* WARNING: Removing unreachable block (ram,0x81365f3c) */
|
||||
|
||||
void FUN_81365edc(undefined4 param_1,undefined4 param_2,undefined4 param_3,undefined4 param_4,
|
||||
int param_5,undefined4 param_6)
|
||||
|
||||
{
|
||||
bool bVar1;
|
||||
bool bVar2;
|
||||
int *piVar3;
|
||||
int iVar4;
|
||||
undefined4 uVar5;
|
||||
int iVar6;
|
||||
char *pcVar7;
|
||||
int iVar8;
|
||||
|
||||
piVar3 = (int *)FUN_815f94b4();
|
||||
bVar2 = false;
|
||||
bVar1 = false;
|
||||
if (param_5 == 0) {
|
||||
iVar4 = FUN_81365814();
|
||||
if (iVar4 < 0) {
|
||||
iVar4 = 0;
|
||||
goto LAB_813661a0;
|
||||
}
|
||||
bVar2 = true;
|
||||
}
|
||||
uVar5 = (**(code **)(*piVar3 + 0x14))(piVar3,0xe0,0xffffffe0);
|
||||
iVar4 = FUN_81571740();
|
||||
if (-1 < iVar4) {
|
||||
iVar6 = FUN_8152f0d8(param_5,param_6);
|
||||
if (-2 < iVar6) {
|
||||
if (iVar6 == -1) {
|
||||
iVar6 = 0;
|
||||
}
|
||||
FUN_81330230(uVar5,param_5 + iVar6 * 0xd8,0xd8);
|
||||
iVar4 = FUN_815be1b8(param_3,param_4,uVar5,0);
|
||||
if (iVar4 < 0) {
|
||||
FUN_8152e6a0(s_ESMisc__GetValidTicketIndex__ES__81641633,iVar4);
|
||||
LAB_813660e4:
|
||||
(**(code **)(*piVar3 + 0x18))(piVar3,uVar5);
|
||||
if ((bVar2) && (param_5 != 0)) {
|
||||
(**(code **)(*piVar3 + 0x18))(piVar3);
|
||||
}
|
||||
iVar4 = -1;
|
||||
if (bVar1) {
|
||||
iVar4 = iVar6;
|
||||
}
|
||||
goto LAB_813661a0;
|
||||
}
|
||||
pcVar7 = (char *)(**(code **)(*piVar3 + 0x14))(piVar3,0x40,0xffffffe0);
|
||||
iVar8 = FUN_815be250(iVar4,pcVar7,0x40);
|
||||
if (iVar8 == 0x40) {
|
||||
iVar4 = FUN_815be37c(iVar4);
|
||||
if (-1 < iVar4) {
|
||||
if (*pcVar7 == '\0') {
|
||||
FUN_8152e6a0(s_ESMisc__GetValidTicketIndex__No_n_816416a7);
|
||||
(**(code **)(*piVar3 + 0x18))(piVar3,pcVar7);
|
||||
}
|
||||
else {
|
||||
(**(code **)(*piVar3 + 0x18))(piVar3,pcVar7);
|
||||
bVar1 = true;
|
||||
}
|
||||
goto LAB_813660e4;
|
||||
}
|
||||
(**(code **)(*piVar3 + 0x18))(piVar3,pcVar7);
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s_ESMisc__GetValidTicketIndex__ES__8164166f,iVar8);
|
||||
(**(code **)(*piVar3 + 0x18))(piVar3,pcVar7);
|
||||
iVar4 = FUN_815be37c(iVar4);
|
||||
if (-1 < iVar4) goto LAB_813660e4;
|
||||
}
|
||||
}
|
||||
}
|
||||
(**(code **)(*piVar3 + 0x18))(piVar3,uVar5);
|
||||
if ((bVar2) && (param_5 != 0)) {
|
||||
(**(code **)(*piVar3 + 0x18))(piVar3);
|
||||
}
|
||||
FUN_81356514(DAT_810890a0,1,2,0,0,0xffffffff);
|
||||
iVar4 = 0;
|
||||
LAB_813661a0:
|
||||
FUN_815f9500(iVar4);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
=== FUN_81366a2c @ 81366a2c
|
||||
|
||||
void FUN_81366a2c(void)
|
||||
|
||||
{
|
||||
int *piVar1;
|
||||
int iVar2;
|
||||
undefined4 extraout_r4;
|
||||
undefined4 extraout_r4_00;
|
||||
undefined4 uVar3;
|
||||
uint uVar4;
|
||||
undefined4 uVar5;
|
||||
int iVar6;
|
||||
int iVar7;
|
||||
undefined8 uVar8;
|
||||
longlong lVar9;
|
||||
uint local_c8;
|
||||
undefined1 auStack_c4 [196];
|
||||
|
||||
piVar1 = (int *)FUN_815f94b0();
|
||||
iVar7 = 0;
|
||||
iVar2 = FUN_815be4e4(0,&local_c8);
|
||||
if (iVar2 == 0) {
|
||||
if (local_c8 != 0) {
|
||||
iVar7 = (**(code **)(*piVar1 + 0x14))(piVar1,local_c8 * 8 + 0x1f & 0xffffffe0,0xffffffe0);
|
||||
uVar8 = FUN_815be4e4(iVar7,&local_c8);
|
||||
iVar2 = (int)((ulonglong)uVar8 >> 0x20);
|
||||
uVar3 = (undefined4)uVar8;
|
||||
if (iVar2 == 0) {
|
||||
iVar2 = 0;
|
||||
for (uVar4 = 0; uVar4 < local_c8; uVar4 = uVar4 + 1) {
|
||||
iVar6 = *(int *)(iVar7 + iVar2);
|
||||
uVar5 = *(undefined4 *)(iVar7 + iVar2 + 4);
|
||||
if (iVar6 != 1) {
|
||||
lVar9 = FUN_81366758(piVar1,uVar3,iVar6,uVar5);
|
||||
uVar3 = (undefined4)lVar9;
|
||||
if (lVar9 < 0) {
|
||||
FUN_8152e6a0(s__s___s__CheckSafeDeleteTitle_fai_81641ba2,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteEmptyTitles_81641b3e,(int)((ulonglong)lVar9 >> 0x20));
|
||||
uVar3 = extraout_r4;
|
||||
}
|
||||
if ((0xffffffff < lVar9) &&
|
||||
(lVar9 = FUN_81366940(piVar1,uVar3,iVar6,uVar5), uVar3 = (undefined4)lVar9, lVar9 < 0
|
||||
)) {
|
||||
FUN_8152e6a0(s__s___s__DeleteTitle_failed___d_81641bcb,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteEmptyTitles_81641b3e,(int)((ulonglong)lVar9 >> 0x20));
|
||||
uVar3 = extraout_r4_00;
|
||||
}
|
||||
}
|
||||
iVar2 = iVar2 + 8;
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s__ES_ListTitlesOnCard2_fai_81641b79,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteEmptyTitles_81641b3e,iVar2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s__ES_ListTitlesOnCard1_fai_81641b50,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteEmptyTitles_81641b3e,iVar2);
|
||||
}
|
||||
if (iVar7 != 0) {
|
||||
(**(code **)(*piVar1 + 0x18))(piVar1,iVar7);
|
||||
}
|
||||
FUN_81367ae4(auStack_c4,piVar1);
|
||||
iVar2 = FUN_81367b30(auStack_c4,s__title_00000001_00000002_data_tm_81641aa0);
|
||||
if (iVar2 != 0) {
|
||||
FUN_8152e6a0(s__s___s__TMDFile__Open_failed___d_81641beb,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteEmptyTitles_81641b3e,iVar2);
|
||||
}
|
||||
FUN_81367c5c(auStack_c4);
|
||||
FUN_81367c5c(auStack_c4);
|
||||
FUN_815f94fc(iVar2);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
=== FUN_81366c7c @ 81366c7c
|
||||
|
||||
/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */
|
||||
|
||||
void FUN_81366c7c(void)
|
||||
|
||||
{
|
||||
int *piVar1;
|
||||
int iVar2;
|
||||
int iVar3;
|
||||
int iVar4;
|
||||
undefined8 uVar5;
|
||||
undefined2 local_238 [2];
|
||||
int local_234;
|
||||
undefined1 auStack_230 [560];
|
||||
|
||||
uVar5 = FUN_815f94b0();
|
||||
piVar1 = (int *)((ulonglong)uVar5 >> 0x20);
|
||||
iVar2 = (**(code **)(*piVar1 + 0x14))(piVar1,0x4000,0x20);
|
||||
iVar3 = FUN_81535c98();
|
||||
do {
|
||||
iVar4 = FUN_814a0014(iVar2);
|
||||
if (iVar4 == 0) {
|
||||
local_238[0] = 0;
|
||||
iVar3 = FUN_814af408(local_238,1);
|
||||
while (-1 < iVar3) {
|
||||
iVar3 = FUN_814aff5c(auStack_230,local_238[0]);
|
||||
if (iVar3 == 0) {
|
||||
iVar3 = FUN_814af30c(auStack_230,&local_234);
|
||||
if (iVar3 == 0) {
|
||||
if (local_234 == (int)uVar5) {
|
||||
FUN_8152e6a0(s__s___s_found_dl_task_owned_same_t_81641ce2,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteDownloadTask_81641c27,auStack_230);
|
||||
iVar3 = FUN_814afb7c(auStack_230);
|
||||
if (iVar3 == 0) {
|
||||
FUN_8152e6a0(s__s___s_delete_download_task_for_i_81641d10,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteDownloadTask_81641c27,local_238[0]);
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s_NWC24GetDlAppId_failed_____81641caf,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteDownloadTask_81641c27,iVar3);
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s_ignore_title_id__d___08x_81641d3c,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteDownloadTask_81641c27,local_238[0]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s_NWC24GetDlAppId_failed_____81641caf,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteDownloadTask_81641c27,iVar3);
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s_NWC24GetDlTask_failed_____81641c7d,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteDownloadTask_81641c27,iVar3);
|
||||
}
|
||||
iVar3 = FUN_814af408(local_238,0);
|
||||
}
|
||||
iVar3 = FUN_814a0220();
|
||||
if (iVar3 != 0) {
|
||||
FUN_8152e6a0(s__s___s_NWC24CloseLib_failed______81641d5e,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteDownloadTask_81641c27,iVar3);
|
||||
}
|
||||
goto LAB_81366e90;
|
||||
}
|
||||
FUN_8152e6a0(s__s___s_waiting_NWC24Open__81641c3a,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteDownloadTask_81641c27);
|
||||
FUN_81535bcc(0,(_DAT_800000f8 / 4000) * 0x1e);
|
||||
iVar4 = FUN_81535c98();
|
||||
} while ((uint)(iVar4 - iVar3) / (_DAT_800000f8 / 4000) < 0xbb9);
|
||||
iVar3 = -0x1a;
|
||||
FUN_8152e6a0(s__s___s_NWC24Open_failed_with_tim_81641c55,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteDownloadTask_81641c27);
|
||||
LAB_81366e90:
|
||||
if (iVar2 != 0) {
|
||||
(**(code **)(*piVar1 + 0x18))(piVar1,iVar2);
|
||||
}
|
||||
FUN_8152e6a0(s__s___s_delete_download_task_for___81641d8f,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteDownloadTask_81641c27,(int)uVar5);
|
||||
FUN_815f94fc(iVar3);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
=== FUN_81366ee4 @ 81366ee4
|
||||
|
||||
void FUN_81366ee4(undefined4 param_1,undefined4 param_2,undefined4 param_3,uint param_4)
|
||||
|
||||
{
|
||||
undefined4 uVar1;
|
||||
int iVar2;
|
||||
undefined8 uVar3;
|
||||
|
||||
uVar1 = FUN_815f94bc();
|
||||
iVar2 = FUN_81366c10(param_3,param_4);
|
||||
if ((iVar2 != 0) && (iVar2 != -0xc)) {
|
||||
FUN_8152e6a0(s__s___s_failed_to_delete_meta_for_81641dc8,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteTitleContent_81641db5);
|
||||
goto LAB_81367088;
|
||||
}
|
||||
uVar3 = FUN_81366758(uVar1,0x48410000,param_3,param_4);
|
||||
iVar2 = (int)((ulonglong)uVar3 >> 0x20);
|
||||
if ((iVar2 == 1) || ((param_4 & 0xffffff00) == 0x48414f00)) {
|
||||
iVar2 = FUN_81366940(uVar1,(int)uVar3,param_3,param_4);
|
||||
if (iVar2 != 0) {
|
||||
FUN_8152e6a0(s__s___s_failed_to_delete_title_fo_81641df6,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteTitleContent_81641db5);
|
||||
goto LAB_81367088;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (iVar2 != 0) {
|
||||
FUN_8152e6a0(s__s___s_failed_to_check_safety_fo_81641e57,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteTitleContent_81641db5);
|
||||
goto LAB_81367088;
|
||||
}
|
||||
iVar2 = FUN_815bec48(param_3,param_4);
|
||||
if (iVar2 != 0) {
|
||||
FUN_8152e6a0(s__s___s_failed_to_delete_contents_81641e25,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteTitleContent_81641db5);
|
||||
goto LAB_81367088;
|
||||
}
|
||||
}
|
||||
iVar2 = FUN_81366c7c(uVar1,param_4);
|
||||
if (iVar2 != 0) {
|
||||
FUN_8152e6a0(s__s___s_failed_to_delete_DL_task_f_81641e86,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteTitleContent_81641db5);
|
||||
}
|
||||
LAB_81367088:
|
||||
FUN_815f9508(iVar2);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
=== FUN_813670a0 @ 813670a0
|
||||
|
||||
void FUN_813670a0(undefined4 param_1,undefined4 param_2,undefined4 param_3)
|
||||
|
||||
{
|
||||
int iVar1;
|
||||
int iVar2;
|
||||
undefined8 uVar3;
|
||||
undefined8 uVar4;
|
||||
undefined1 auStack_a8 [168];
|
||||
|
||||
uVar3 = FUN_815f94c4();
|
||||
FUN_81367ae4(auStack_a8,param_3);
|
||||
uVar4 = FUN_81367b30(auStack_a8,s__title_00000001_00000002_data_tm_81641aa0);
|
||||
iVar1 = (int)((ulonglong)uVar4 >> 0x20);
|
||||
if (iVar1 == 0) {
|
||||
iVar1 = FUN_813680ac(auStack_a8,(int)uVar4,(int)((ulonglong)uVar3 >> 0x20),(int)uVar3);
|
||||
if (iVar1 == -0x401) {
|
||||
FUN_8152e6a0(s__s___s__No_backup_of__016llx___d_81641ef0,s_iplESMisc_cpp_816418fc,
|
||||
s_PrepareTitleDir_81641eb7);
|
||||
}
|
||||
else if (iVar1 != 0) {
|
||||
FUN_8152e6a0(s__s___s__Restore_failed___d_81641f12,s_iplESMisc_cpp_816418fc,
|
||||
s_PrepareTitleDir_81641eb7,iVar1);
|
||||
}
|
||||
iVar2 = FUN_81367c5c(auStack_a8);
|
||||
if (iVar2 != 0) {
|
||||
FUN_8152e6a0(s__s___s__Failed_to_close_TMD_syst_81641f2e,s_iplESMisc_cpp_816418fc,
|
||||
s_PrepareTitleDir_81641eb7,iVar2);
|
||||
iVar1 = iVar2;
|
||||
}
|
||||
FUN_81367c5c(auStack_a8);
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s__Open_backup_TMD_file_fai_81641ec7,s_iplESMisc_cpp_816418fc,
|
||||
s_PrepareTitleDir_81641eb7,iVar1);
|
||||
FUN_81367c5c(auStack_a8);
|
||||
}
|
||||
FUN_815f9510(iVar1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
=== FUN_813671c4 @ 813671c4
|
||||
|
||||
void FUN_813671c4(undefined4 param_1,undefined4 param_2,int *param_3)
|
||||
|
||||
{
|
||||
int iVar1;
|
||||
int iVar2;
|
||||
int unaff_r13;
|
||||
uint uVar3;
|
||||
int iVar4;
|
||||
int iVar5;
|
||||
undefined8 uVar6;
|
||||
uint auStack_100 [8];
|
||||
undefined1 auStack_e0 [64];
|
||||
undefined1 uStack_a0;
|
||||
undefined1 auStack_80 [128];
|
||||
|
||||
uVar6 = FUN_815f94b8();
|
||||
iVar5 = 0;
|
||||
auStack_100[0] = 0;
|
||||
FUN_81600a80(auStack_80,s__title__08x__08x_data__81641f6a,(int)((ulonglong)uVar6 >> 0x20),
|
||||
(int)uVar6);
|
||||
iVar1 = FUN_81564310(auStack_80,0,auStack_100);
|
||||
if ((iVar1 == 0) && (auStack_100[0] != 0)) {
|
||||
iVar5 = (**(code **)(*param_3 + 0x14))
|
||||
(param_3,auStack_100[0] * 0x41 + 0x1f & 0xffffffe0,0xffffffe0);
|
||||
if (iVar5 == 0) {
|
||||
iVar1 = -2;
|
||||
FUN_8152e6a0(s__s___s__Could_not_alloc___d_81641fa1,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteSavedata_81641f5b,0xfffffffe);
|
||||
}
|
||||
else {
|
||||
iVar1 = FUN_81564310(auStack_80,iVar5,auStack_100);
|
||||
if (iVar1 == 0) {
|
||||
iVar4 = iVar5;
|
||||
for (uVar3 = 0; uVar3 < auStack_100[0]; uVar3 = uVar3 + 1) {
|
||||
FUN_816009a8(auStack_e0,0x40,unaff_r13 + -0x7da0,auStack_80,iVar4);
|
||||
uStack_a0 = 0;
|
||||
iVar1 = FUN_81563ea8(auStack_e0);
|
||||
if (iVar1 != 0) {
|
||||
FUN_8152e6a0(s__s___s__Failed_to_delete__s___d_81641fde,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteSavedata_81641f5b,auStack_e0,iVar1);
|
||||
}
|
||||
iVar2 = FUN_815f8efc(iVar4);
|
||||
iVar4 = iVar2 + iVar4 + 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s__Could_not_read2__s___d_81641fbe,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteSavedata_81641f5b,auStack_80,iVar1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s__Could_not_read1__s___d_81641f81,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteSavedata_81641f5b,auStack_80,iVar1);
|
||||
}
|
||||
if (iVar5 != 0) {
|
||||
(**(code **)(*param_3 + 0x18))(param_3,iVar5);
|
||||
}
|
||||
FUN_815f9504(iVar1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
=== FUN_813673e0 @ 813673e0
|
||||
|
||||
void FUN_813673e0(void)
|
||||
|
||||
{
|
||||
bool bVar1;
|
||||
bool bVar2;
|
||||
int *piVar3;
|
||||
int iVar4;
|
||||
int iVar5;
|
||||
int iVar6;
|
||||
undefined4 extraout_r4;
|
||||
int iVar7;
|
||||
undefined4 uVar8;
|
||||
undefined4 uVar9;
|
||||
uint uVar10;
|
||||
uint uVar11;
|
||||
uint uVar12;
|
||||
int iVar13;
|
||||
uint uVar14;
|
||||
int iVar15;
|
||||
int iVar16;
|
||||
uint uStack_240;
|
||||
uint uStack_23c;
|
||||
undefined1 auStack_238 [88];
|
||||
undefined1 auStack_1e0 [4];
|
||||
undefined4 uStack_1dc;
|
||||
undefined4 uStack_1d8;
|
||||
undefined1 auStack_100 [256];
|
||||
|
||||
piVar3 = (int *)FUN_815f948c();
|
||||
iVar15 = 0;
|
||||
uStack_23c = 0;
|
||||
iVar4 = FUN_815be4e4(0,&uStack_23c);
|
||||
if (iVar4 == 0) {
|
||||
iVar15 = (**(code **)(*piVar3 + 0x14))(piVar3,uStack_23c * 8 + 0x1f & 0xffffffe0,0xffffffe0);
|
||||
if (iVar15 == 0) {
|
||||
FUN_8152e6a0(s__s___s__Unable_to_allocate_8164205c,s_iplESMisc_cpp_816418fc,
|
||||
s_InitSavedata_81642023);
|
||||
}
|
||||
else {
|
||||
iVar4 = FUN_815be4e4(iVar15,&uStack_23c);
|
||||
if (iVar4 == 0) {
|
||||
iVar13 = 0;
|
||||
for (uVar14 = 0; uVar14 < uStack_23c; uVar14 = uVar14 + 1) {
|
||||
uVar12 = *(uint *)(iVar15 + iVar13);
|
||||
uVar11 = *(uint *)(iVar15 + iVar13 + 4);
|
||||
if ((uVar11 & 0xffffff00) == 0x525a4400 && uVar12 == 0x10000) {
|
||||
iVar16 = 0;
|
||||
bVar1 = false;
|
||||
bVar2 = false;
|
||||
FUN_81600a80(auStack_238,s__title__08x__08x_data__s_816420a4,uVar12 & 0xffffff,uVar11,
|
||||
s_zeldaTp_dat_816420bd);
|
||||
iVar5 = FUN_81366610(uVar12,uVar11);
|
||||
if (iVar5 == 0) {
|
||||
FUN_8152e6a0(s__s___s__ChangeUid_failed_816420c9,s_iplESMisc_cpp_816418fc,
|
||||
s_verifySavedataZD_81641fff);
|
||||
FUN_81366940(piVar3,extraout_r4,uVar12,uVar11);
|
||||
}
|
||||
else {
|
||||
iVar5 = FUN_815652f8(auStack_238,auStack_100,1);
|
||||
if (iVar5 == -0xc) {
|
||||
FUN_8152e6a0(s__s___s__Does_not_exist__s___d_816420e3,s_iplESMisc_cpp_816418fc,
|
||||
s_verifySavedataZD_81641fff,auStack_238,0xfffffff4);
|
||||
}
|
||||
else if (iVar5 == 0) {
|
||||
bVar1 = true;
|
||||
iVar16 = (**(code **)(*piVar3 + 0x14))(piVar3,0x4000,0xffffffe0);
|
||||
if (iVar16 == 0) {
|
||||
FUN_8152e6a0(s__s___s__Alloc_failed___d_8164212a,s_iplESMisc_cpp_816418fc,
|
||||
s_verifySavedataZD_81641fff,0xfffffffe);
|
||||
}
|
||||
else {
|
||||
FUN_81330334(iVar16,0,0x4000);
|
||||
iVar5 = FUN_81564000(auStack_100,iVar16,0x4000);
|
||||
if (iVar5 < 0) {
|
||||
FUN_8152e6a0(s__s___s__Read_file_failed___d_81642144,s_iplESMisc_cpp_816418fc,
|
||||
s_verifySavedataZD_81641fff,iVar5);
|
||||
}
|
||||
else {
|
||||
if (iVar5 == 0x4000) {
|
||||
iVar5 = 8;
|
||||
bVar1 = false;
|
||||
uVar10 = 0;
|
||||
do {
|
||||
iVar7 = iVar16 + iVar5;
|
||||
iVar6 = FUN_813673b0(iVar7 + 0x4e,8);
|
||||
if (((((iVar6 == 0) || (iVar6 = FUN_813673b0(iVar7 + 0x58,8), iVar6 == 0))
|
||||
|| (iVar6 = FUN_813673b0(iVar7 + 0x72,8), iVar6 == 0)) ||
|
||||
((iVar6 = FUN_813673b0(iVar7 + 0x8e,8), iVar6 == 0 ||
|
||||
(iVar6 = FUN_813673b0(iVar7 + 0x1b4,0x11), iVar6 == 0)))) ||
|
||||
(iVar6 = FUN_813673b0(iVar7 + 0x1c5,0x11), iVar6 == 0))
|
||||
goto LAB_813677bc;
|
||||
uVar10 = uVar10 + 1;
|
||||
iVar5 = iVar5 + 0xa94;
|
||||
} while (uVar10 < 3);
|
||||
iVar5 = 0x2008;
|
||||
uVar10 = 0;
|
||||
do {
|
||||
iVar7 = iVar16 + iVar5;
|
||||
iVar6 = FUN_813673b0(iVar7 + 0x4e,8);
|
||||
if (((iVar6 == 0) || (iVar6 = FUN_813673b0(iVar7 + 0x58,8), iVar6 == 0)) ||
|
||||
((iVar6 = FUN_813673b0(iVar7 + 0x72,8), iVar6 == 0 ||
|
||||
(((iVar6 = FUN_813673b0(iVar7 + 0x8e,8), iVar6 == 0 ||
|
||||
(iVar6 = FUN_813673b0(iVar7 + 0x1b4,0x11), iVar6 == 0)) ||
|
||||
(iVar6 = FUN_813673b0(iVar7 + 0x1c5,0x11), iVar6 == 0))))))
|
||||
goto LAB_813677bc;
|
||||
uVar10 = uVar10 + 1;
|
||||
iVar5 = iVar5 + 0xa94;
|
||||
} while (uVar10 < 3);
|
||||
bVar1 = true;
|
||||
LAB_813677bc:
|
||||
if (!bVar1) {
|
||||
FUN_8152e6a0(s__s___s__Verify_failed_for__016ll_81642188,
|
||||
s_iplESMisc_cpp_816418fc,s_verifySavedataZD_81641fff);
|
||||
bVar2 = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s__File_size_is_not_correct_81642162,
|
||||
s_iplESMisc_cpp_816418fc,s_verifySavedataZD_81641fff,iVar5);
|
||||
bVar2 = true;
|
||||
}
|
||||
FUN_815654ec(auStack_100);
|
||||
bVar1 = false;
|
||||
if (bVar2) {
|
||||
FUN_813671c4(uVar12,uVar11,piVar3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s__Open_save_data_file_fail_81642102,s_iplESMisc_cpp_816418fc,
|
||||
s_verifySavedataZD_81641fff,iVar5);
|
||||
}
|
||||
}
|
||||
if (iVar16 != 0) {
|
||||
(**(code **)(*piVar3 + 0x18))(piVar3,iVar16);
|
||||
}
|
||||
if (bVar1) {
|
||||
FUN_815654ec(auStack_100);
|
||||
}
|
||||
FUN_81366610(1,2);
|
||||
goto LAB_81367a90;
|
||||
}
|
||||
if (uVar11 == 0x44495343 && uVar12 == 0x10008) {
|
||||
LAB_81367930:
|
||||
FUN_815bed3c(*(undefined4 *)(iVar15 + iVar13),*(undefined4 *)(iVar15 + iVar13 + 4));
|
||||
uVar8 = *(undefined4 *)(iVar15 + iVar13);
|
||||
uVar9 = *(undefined4 *)(iVar15 + iVar13 + 4);
|
||||
iVar16 = 0;
|
||||
FUN_81330334(auStack_1e0,0,0xe0);
|
||||
iVar5 = FUN_815be908(uVar8,uVar9,0,&uStack_240);
|
||||
if (iVar5 == 0) {
|
||||
if (uStack_240 == 0) goto LAB_81367a90;
|
||||
iVar16 = (**(code **)(*piVar3 + 0x14))(piVar3,uStack_240 * 0xe0,0xffffffe0);
|
||||
iVar5 = FUN_815be908(uVar8,uVar9,iVar16,&uStack_240);
|
||||
if (iVar5 == 0) {
|
||||
iVar5 = 0;
|
||||
for (uVar11 = 0; uVar11 < uStack_240; uVar11 = uVar11 + 1) {
|
||||
FUN_81330230(auStack_1e0,iVar16 + iVar5,0xd8);
|
||||
iVar6 = FUN_815bedac(auStack_1e0);
|
||||
if (iVar6 != 0) {
|
||||
FUN_8152e6a0(s__s___s__ES_DeleteTicket_failed____816421dd,
|
||||
s_iplESMisc_cpp_816418fc,s_DeleteTicketsForce_81642010,iVar6,
|
||||
uStack_1dc,uStack_1d8);
|
||||
}
|
||||
iVar5 = iVar5 + 0xd8;
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s__ES_GetTicketViews_failed_816421ab,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteTicketsForce_81642010,iVar5,uVar8,uVar9);
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s__ES_GetTicketViews_failed_816421ab,s_iplESMisc_cpp_816418fc,
|
||||
s_DeleteTicketsForce_81642010,iVar5,uVar8,uVar9);
|
||||
}
|
||||
if (iVar16 != 0) {
|
||||
(**(code **)(*piVar3 + 0x18))(piVar3,iVar16);
|
||||
}
|
||||
}
|
||||
else if (uVar12 < 0x10008 || uVar12 - 0x10008 < (uint)(uVar11 < 0x44495343)) {
|
||||
if ((uVar11 == 0x4a4f4449 && uVar12 == 0x10001) ||
|
||||
((uVar12 < 0x10001 || uVar12 - 0x10001 < (uint)(uVar11 < 0x4a4f4449) &&
|
||||
(uVar11 == 0x48415858 && uVar12 == 0x10001)))) goto LAB_81367930;
|
||||
}
|
||||
else if ((uVar11 == 0x44564458 && uVar12 == 0x10008) ||
|
||||
((uVar12 < 0x10008 || uVar12 - 0x10008 < (uint)(uVar11 < 0x44564458) &&
|
||||
(uVar11 == 0x4449534b && uVar12 == 0x10008)))) goto LAB_81367930;
|
||||
LAB_81367a90:
|
||||
iVar13 = iVar13 + 8;
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s__Failed_to_ES_ListTitlesO_81642078,s_iplESMisc_cpp_816418fc,
|
||||
s_InitSavedata_81642023,iVar4);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
FUN_8152e6a0(s__s___s__Failed_to_ES_ListTitlesO_81642030,s_iplESMisc_cpp_816418fc,
|
||||
s_InitSavedata_81642023,iVar4);
|
||||
}
|
||||
if (iVar15 != 0) {
|
||||
(**(code **)(*piVar3 + 0x18))(piVar3,iVar15);
|
||||
}
|
||||
FUN_815f94d8(iVar4);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
880
tools/decomp-assist/iplESMisc.reference.cpp
Normal file
880
tools/decomp-assist/iplESMisc.reference.cpp
Normal file
@@ -0,0 +1,880 @@
|
||||
#include "utility/iplESMisc.h"
|
||||
#include "BS2/BS2.h"
|
||||
|
||||
#include "system/iplSystem.h"
|
||||
#include "system/iplErrorHandler.h"
|
||||
|
||||
#include <private/es.h>
|
||||
|
||||
#include <revolution/sc.h>
|
||||
|
||||
#include <private/nand.h>
|
||||
#include <revolution/nand.h>
|
||||
|
||||
#include <private/os.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define TMD_FILE "/title/00000001/00000002/data/tmds.sys"
|
||||
|
||||
namespace ipl {
|
||||
namespace utility {
|
||||
// meh
|
||||
#define ES_ERR_REPORT(msg, ...) OSReport("%s::%s: " msg "\n", __FILE__, __FUNCTION__, __VA_ARGS__);
|
||||
|
||||
ESError ESMisc::GetTmdView(EGG::Heap* heap, ESTitleId titleId, ESTmdView** outTmdView) {
|
||||
ESTmdView* tmdView;
|
||||
u32 tmdViewSize = 0;
|
||||
|
||||
ESError ret;
|
||||
|
||||
ret = ES_GetTmdView(titleId, NULL, &tmdViewSize);
|
||||
if (ret < ES_ERR_OK) {
|
||||
OSReport("ESMisc::GetTmdView: ES_GetTmdView1 err %d\n", ret);
|
||||
*outTmdView = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
tmdView = (ESTmdView*)heap->alloc(OSRoundUp32B(tmdViewSize), -DEFAULT_ALIGN);
|
||||
*outTmdView = tmdView;
|
||||
memset(tmdView, 0, OSRoundUp32B(tmdViewSize));
|
||||
|
||||
ret = ES_GetTmdView(titleId, *outTmdView, &tmdViewSize);
|
||||
if (ret < ES_ERR_OK) {
|
||||
OSReport("ESMisc::GetTmdView: ES_GetTmdView2 err %d\n", ret);
|
||||
heap->free(*outTmdView);
|
||||
*outTmdView = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
ESError ESMisc::GetTicketViewList(EGG::Heap* heap, ESTitleId titleId, ESTicketView** outTicketViews, u32* outNumTicketViews) {
|
||||
ESTicketView* ticketViews;
|
||||
u32 numTicketViews = 0;
|
||||
|
||||
ESError ret;
|
||||
|
||||
ret = ES_GetTicketViews(titleId, NULL, &numTicketViews);
|
||||
if (ret < ES_ERR_OK) {
|
||||
OSReport("ESMisc::GetTicketViewList: ES_GetTicketViews1 err %d\n", ret);
|
||||
*outTicketViews = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (outNumTicketViews) {
|
||||
*outNumTicketViews = numTicketViews;
|
||||
}
|
||||
|
||||
if (numTicketViews == 0) {
|
||||
return ES_ERR_TICKET_NOT_FOUND;
|
||||
}
|
||||
|
||||
ticketViews = (ESTicketView*)heap->alloc(OSRoundUp32B(numTicketViews * sizeof(ESTicketView)), -DEFAULT_ALIGN);
|
||||
*outTicketViews = ticketViews;
|
||||
|
||||
ret = ES_GetTicketViews(titleId, ticketViews, &numTicketViews);
|
||||
if (ret < ES_ERR_OK) {
|
||||
OSReport("ESMisc::GetTicketViewList: ES_GetTicketViews2 err %d\n", ret);
|
||||
heap->free(*outTicketViews);
|
||||
*outTicketViews = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ES_ERR_OK;
|
||||
}
|
||||
|
||||
ESError ESMisc::GetTicketView(EGG::Heap* heap, ESTitleId titleId, ESTicketView* ticketView, int numTicketViews) {
|
||||
u32 inNumTicketViews = 0;
|
||||
ESTicketView* inTicketView = NULL;
|
||||
|
||||
ESError ret;
|
||||
|
||||
ret = GetTicketViewList(heap, titleId, &inTicketView, &inNumTicketViews);
|
||||
if (numTicketViews >= inNumTicketViews) {
|
||||
OSReport("ESMisc::GetTicketView: Invalid index %d\n", numTicketViews);
|
||||
ret = ES_ERR_TICKET_NOT_FOUND;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (ret == ES_ERR_OK) {
|
||||
memcpy(ticketView, inTicketView + numTicketViews, sizeof(ESTicketView));
|
||||
}
|
||||
out:
|
||||
if (inTicketView != NULL) {
|
||||
heap->free(inTicketView);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 ESMisc::PrivateContentsExist(ESTitleId titleId) {
|
||||
char path[96] ALIGN32;
|
||||
|
||||
u32 usedBlocks = 0;
|
||||
u32 usedINodes = 0;
|
||||
|
||||
s32 ret;
|
||||
|
||||
sprintf(path, "/title/%08x/%08x/content", NANDTitleIdHi(titleId), NANDTitleIdLo(titleId));
|
||||
ret = NANDSecretGetUsage(path, &usedBlocks, &usedINodes);
|
||||
if (ret != NAND_RESULT_OK || usedINodes <= 2) {
|
||||
if (ret != NAND_RESULT_OK && ret != NAND_RESULT_NOEXISTS) {
|
||||
OSReport("ESMisc::PrivateContentsExist: err %d\n", ret);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return usedINodes - 2;
|
||||
}
|
||||
|
||||
BOOL ESMisc::ContentExist(ESTmdView* tmdView, u32 contentIndex, s32* result) {
|
||||
u32 numContents;
|
||||
u32 contents[512] ALIGN32;
|
||||
|
||||
ESTitleId titleId = tmdView->head.titleId;
|
||||
|
||||
u32 i, cid;
|
||||
|
||||
for (i = 0; i < tmdView->head.numContents; i++) {
|
||||
// Find CID of index
|
||||
if (contentIndex == tmdView->contents[i].index) {
|
||||
cid = tmdView->contents[i].cid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we have overflown.
|
||||
if (i == tmdView->head.numContents) {
|
||||
*result = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Get number of contents
|
||||
s32 ret = ES_ListTitleContentsOnCard(titleId, NULL, &numContents);
|
||||
if (ret != ES_ERR_OK) {
|
||||
OSReport("ESMisc::ContentExist: ES_ListTitleContentsOnCard1 err %d\n", ret);
|
||||
if (result) {
|
||||
*result = ret;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Get list of CIDs
|
||||
ret = ES_ListTitleContentsOnCard(titleId, contents, &numContents);
|
||||
if (ret != ES_ERR_OK) {
|
||||
OSReport("ESMisc::ContentExist: ES_ListTitleContentsOnCard2 err %d\n", ret);
|
||||
if (result) {
|
||||
*result = ret;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// For each CID
|
||||
for (int j = 0; j < numContents; j++) {
|
||||
// Compare...
|
||||
if (cid == contents[j]) {
|
||||
// We got it!
|
||||
if (result) {
|
||||
*result = 0;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// We don't got it...
|
||||
if (result) {
|
||||
*result = 0;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ESError ESMisc::checkContentsNum(ESTitleId titleId, ESTmdView* tmdView) {
|
||||
s32 result = 0;
|
||||
u32 numContents = 0;
|
||||
ESContentId contentIds[ES_MAX_CONTENT] ALIGN32;
|
||||
|
||||
s32 privateCount = PrivateContentsExist(titleId);
|
||||
|
||||
if (privateCount == 0) {
|
||||
OSReport("ESMisc::checkContentsNum: no TMD or content for 0x%016llx.\n", titleId);
|
||||
return 1;
|
||||
} else {
|
||||
u16 num = tmdView->head.numContents;
|
||||
u32 i;
|
||||
s32 count = 0;
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
if ((tmdView->contents[i].type & 0x8000) == 0) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (privateCount == count) {
|
||||
result = 0;
|
||||
} else {
|
||||
ESError err = ES_ListTitleContentsOnCard(titleId, NULL, &numContents);
|
||||
result = err;
|
||||
|
||||
if (err != ES_ERR_OK) {
|
||||
OSReport("ESMisc::checkContentsNum: ES_ListTitleContentsOnCard err %d\n", err);
|
||||
} else if (numContents == 0) {
|
||||
OSReport("ESMisc::checkContentsNum: no content for 0x%016llx.\n", titleId);
|
||||
result = 1;
|
||||
} else {
|
||||
err = ES_ListTitleContentsOnCard(titleId, contentIds, &numContents);
|
||||
result = err;
|
||||
|
||||
if (err == ES_ERR_OK) {
|
||||
bool found = false;
|
||||
|
||||
for (i = 0; i < numContents && !found; i++) {
|
||||
for (u32 j = 0; j < num; j++) {
|
||||
if (contentIds[i] == tmdView->contents[j].cid && (tmdView->contents[j].type & 0x8000) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
OSReport("ESMisc::checkContentsNum: 0x%016llx is already deleted.\n", titleId);
|
||||
result = 1;
|
||||
} else {
|
||||
for (u32 j = 0; j < num; j++) {
|
||||
u32 k = 0;
|
||||
for (i = 0; i < numContents; i++) {
|
||||
if (contentIds[i] == tmdView->contents[j].cid) {
|
||||
break;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
if (k == numContents && (tmdView->contents[j].type & 0x4000) == 0) {
|
||||
OSReport("ESMisc::checkContentsNum: not complete: non-optional cidx %d missing for 0x%016llx.\n",
|
||||
tmdView->contents[j].index, titleId);
|
||||
result = 2;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
OSReport("ESMisc::checkContentsNum: complete: only missing non-optional contents for 0x%016llx.\n", titleId);
|
||||
result = 0;
|
||||
}
|
||||
} else {
|
||||
OSReport("ESMisc::checkContentsNum: ES_ListTitleContentsOnCard failed.[%d]\n", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
return result;
|
||||
}
|
||||
|
||||
ESError ESMisc::GetValidTicketIndex(EGG::Heap* heap, ESTitleId titleId, ESTicketView* ticket, u32 ticketLength) {
|
||||
bool allocated = false;
|
||||
bool found = false;
|
||||
ESTicketView* ticketView;
|
||||
s32 index;
|
||||
|
||||
if (ticket == NULL) {
|
||||
if (GetTicketViewList(heap, titleId, &ticket, &ticketLength) < 0) {
|
||||
if (ticket != NULL) {
|
||||
heap->free(ticket);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
allocated = true;
|
||||
}
|
||||
|
||||
ticketView = (ESTicketView*)heap->alloc(0xe0, -32);
|
||||
|
||||
if (ESP_InitLib() < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
index = __OSGetValidTicketIndex(ticket, ticketLength);
|
||||
|
||||
if (index < -1) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (index == -1) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
memcpy(ticketView, (u8*)ticket + index * 0xd8, 0xd8);
|
||||
|
||||
{
|
||||
ESFd fd = ES_OpenTitleContentFile(titleId, ticketView, 0);
|
||||
|
||||
if (fd < 0) {
|
||||
OSReport("ESMisc::GetValidTicketIndex: ES_OpenTitleContentFile fd %d\n", fd);
|
||||
} else {
|
||||
u8* buf = (u8*)heap->alloc(0x40, 32);
|
||||
s32 numRead = ES_ReadContentFile(fd, buf, 0x40);
|
||||
|
||||
if (numRead != 0x40) {
|
||||
OSReport("ESMisc::GetValidTicketIndex: ES_ReadContentFile err %d\n", numRead);
|
||||
heap->free(buf);
|
||||
|
||||
if (ES_CloseContentFile(fd) < 0) {
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
if (ES_CloseContentFile(fd) < 0) {
|
||||
heap->free(buf);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (buf[0] == 0) {
|
||||
OSReport("ESMisc::GetValidTicketIndex: No name\n");
|
||||
heap->free(buf);
|
||||
} else {
|
||||
heap->free(buf);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
heap->free(ticketView);
|
||||
|
||||
if (allocated && ticket != NULL) {
|
||||
heap->free(ticket);
|
||||
}
|
||||
|
||||
return found ? index : -1;
|
||||
|
||||
error:
|
||||
heap->free(ticketView);
|
||||
|
||||
if (allocated && ticket != NULL) {
|
||||
heap->free(ticket);
|
||||
}
|
||||
|
||||
System::getErrorHandler()->set(ErrorHandler::DEFAULT, MESG_ERR_FILE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// DeleteSharedContent did not survive
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: MEMAllocate for TMD err\n");
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: ES_ListSharedContents1 err %d\n");
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: MEMAllocate for SHA-1 hash err\n");
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: ES_ListSharedContents2 err %d\n");
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: ES_ListTitlesOnCard1 err %d\n");
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: MEMAllocate for Title List err\n");
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: MEMAllocate for Title List err\n");
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: ES_ListTitlesOnCard2 err %d\n");
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: ES_GetTmd1 err %d\n");
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: ES_GetTmd2 err %d\n");
|
||||
DECOMP_FORCE_ACTIVE(iplESMisc_cpp, "DeleteSharedContent: ES_DeleteSharedContent err %d\n");
|
||||
|
||||
BOOL ESMisc::IsLastTicketExpired(ESTitleId* titleId) {
|
||||
s32 ret;
|
||||
NANDFileInfo file;
|
||||
ESTitleId readTitleId ALIGN32;
|
||||
|
||||
if (BS2GetBootType() != 1) {
|
||||
DeleteExpiredFlagFile();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ret = NANDPrivateOpen("/shared2/expired", &file, NAND_ACCESS_READ);
|
||||
if (ret == NAND_RESULT_NOEXISTS) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (ret != NAND_RESULT_OK) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
s32 read = NANDRead(&file, &readTitleId, OSRoundUp32B(sizeof(readTitleId)));
|
||||
NANDClose(&file);
|
||||
if (read != (s32)OSRoundUp32B(sizeof(readTitleId))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (titleId) {
|
||||
*titleId = readTitleId;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void ESMisc::DeleteExpiredFlagFile() {
|
||||
NANDPrivateDelete("/shared2/expired");
|
||||
}
|
||||
|
||||
u32 ESMisc::CheckTmdCountryCode(ESTmdView* tmdView) {
|
||||
return __OSCheckTmdCountryCode(tmdView);
|
||||
}
|
||||
|
||||
// Copied from BS2
|
||||
BOOL ESMisc::__IsPCEnable() {
|
||||
switch (SCGetProductArea()) {
|
||||
case SC_PRODUCT_AREA_JPN:
|
||||
case SC_PRODUCT_AREA_USA:
|
||||
case SC_PRODUCT_AREA_EUR:
|
||||
case SC_PRODUCT_AREA_AUS:
|
||||
case SC_PRODUCT_AREA_TWN:
|
||||
case SC_PRODUCT_AREA_KOR: {
|
||||
return TRUE;
|
||||
}
|
||||
default: {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 ESMisc::CheckTmdParentalControl(ESTmdView* tmdView) {
|
||||
if (!__IsPCEnable()) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
u8 ratings[16];
|
||||
memcpy(ratings, tmdView->head.reserved.ratings, 16);
|
||||
|
||||
SCParentalControlsInfo pcInfo;
|
||||
if (!SCGetParentalControl(&pcInfo)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (pcInfo.enable & SC_PARENTAL_FLAG_ENABLED) {
|
||||
u8 rating = ratings[pcInfo.org];
|
||||
|
||||
if (rating & SC_PARENTAL_FLAG_ENABLED) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (rating & 0x40) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((rating & SC_PARENTAL_RATING_ENABLED) > pcInfo.rating) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ESError ESMisc::NumPrivateContents(EGG::Heap* heap, ESTitleId titleId) {
|
||||
ESTmdView* tmdView = NULL;
|
||||
ESContentId* contentIds = NULL;
|
||||
u32 numContents;
|
||||
u32 tmdViewSize;
|
||||
|
||||
ESError ret = ES_GetTmdView(titleId, NULL, &tmdViewSize);
|
||||
if (ret == ES_ERR_DONT_EXISTS) {
|
||||
return ES_ERR_OK;
|
||||
}
|
||||
|
||||
if (ret < ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_GetTmdView1 failed: %d", ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = ES_ListTitleContentsOnCard(titleId, NULL, &numContents);
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_ListTitleContentsOnCard1 failed: %d for %016llx", ret, titleId);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (numContents == 0) {
|
||||
return ES_ERR_OK;
|
||||
}
|
||||
|
||||
tmdView = (ESTmdView*)heap->alloc(OSRoundUp32B(tmdViewSize), -DEFAULT_ALIGN);
|
||||
contentIds = (ESContentId*)heap->alloc(OSRoundUp32B(numContents * sizeof(ESContentId)), -DEFAULT_ALIGN);
|
||||
|
||||
ret = ES_ListTitleContentsOnCard(titleId, contentIds, &numContents);
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_ListTitleContentsOnCard2 failed: %d for %016llx", ret, titleId);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = ES_GetTmdView(titleId, tmdView, &tmdViewSize);
|
||||
if (ret < ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_GetTmdView2 failed: %d", ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
u32 j = 0;
|
||||
for (u32 i = 0; i < tmdView->head.numContents && j < numContents; i++) {
|
||||
if (tmdView->contents[i].cid == contentIds[j]) {
|
||||
if (!(tmdView->contents[i].type & 0x8000)) {
|
||||
ret++;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (contentIds != NULL) {
|
||||
heap->free(contentIds);
|
||||
}
|
||||
if (tmdView != NULL) {
|
||||
heap->free(tmdView);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL ESMisc::ChangeUid(ESTitleId titleId) {
|
||||
s32 ret = ES_SetUid(titleId);
|
||||
if (ret != ES_ERR_OK) {
|
||||
OSReport("ES_SetUid failed[%d]: 0x%016llx\n", ret, titleId);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Reinitialize FS library
|
||||
ISFS_CloseLib();
|
||||
ISFS_OpenLib();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
u32 ESMisc::NumInodesSaveDirRoot(ESTitleId titleId) {
|
||||
s32 result = -1;
|
||||
bool changedUid = false;
|
||||
|
||||
if (ChangeUid(titleId)) {
|
||||
changedUid = true;
|
||||
|
||||
char path[64] ALIGN32;
|
||||
snprintf(path, sizeof(path), "/title/%08x/%08x/data", NANDTitleIdHi(titleId), NANDTitleIdLo(titleId));
|
||||
|
||||
u32 nodes;
|
||||
s32 ret = NANDPrivateReadDir(path, NULL, &nodes);
|
||||
|
||||
if (ret != NAND_RESULT_OK) {
|
||||
ES_ERR_REPORT("NANDReadDir failed: %d", ret);
|
||||
result = ret;
|
||||
goto out;
|
||||
}
|
||||
|
||||
result = nodes;
|
||||
}
|
||||
out:
|
||||
if (changedUid) {
|
||||
ChangeUid(SYSMENU_TITLE_ID);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
s32 ESMisc::CheckSafeDeleteTitle(EGG::Heap* heap, ESTitleId titleId) {
|
||||
s32 result;
|
||||
ESTmdView* tmdView = NULL;
|
||||
u32 tmdViewSize;
|
||||
|
||||
if (PrivateContentsExist(titleId) != 0) {
|
||||
ES_ERR_REPORT("%016llx is not empry", titleId);
|
||||
result = 0;
|
||||
} else {
|
||||
result = NumPrivateContents(heap, titleId);
|
||||
|
||||
if (result < 0) {
|
||||
ES_ERR_REPORT("NumPrivateContents failed: %d", result);
|
||||
} else if (result > 0) {
|
||||
result = 0;
|
||||
} else {
|
||||
ESError err = ES_GetTmdView(titleId, NULL, &tmdViewSize);
|
||||
result = err;
|
||||
|
||||
if (err == ES_ERR_DONT_EXISTS) {
|
||||
result = ES_ERR_OK;
|
||||
} else if (err != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_GetTmdView1 failed: %d", err);
|
||||
} else {
|
||||
tmdView = (ESTmdView*)heap->alloc(OSRoundUp32B(tmdViewSize), -DEFAULT_ALIGN);
|
||||
result = ES_GetTmdView(titleId, tmdView, &tmdViewSize);
|
||||
|
||||
if (result != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_GetTmdView2 failed: %d", result);
|
||||
} else if ((tmdView->head.titleVersion >> 8) != 0) {
|
||||
result = 0;
|
||||
} else {
|
||||
result = NumInodesSaveDirRoot(titleId);
|
||||
|
||||
if (result < 0) {
|
||||
ES_ERR_REPORT("NumInodesSaveDirRoot failed: %d", result);
|
||||
} else {
|
||||
result = (result == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tmdView != NULL) {
|
||||
heap->free(tmdView);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
s32 ESMisc::DeleteTitle(EGG::Heap* heap, ESTitleId titleId) {
|
||||
TMDFile tmdFile(heap);
|
||||
|
||||
s32 ret = tmdFile.Open((char*)TMD_FILE);
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("Open TMD Backup file failed: %d", ret);
|
||||
goto do_proc;
|
||||
}
|
||||
|
||||
ret = tmdFile.Backup(titleId);
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("Backup TMD failed: %d", ret);
|
||||
goto do_proc;
|
||||
}
|
||||
do_proc:
|
||||
ret = ES_DeleteTitle(titleId);
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_DeleteTitle failed: %d for %016llx", ret, titleId);
|
||||
}
|
||||
tmdFile.Close();
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 ESMisc::DeleteMetaContent(ESTitleId titleId) {
|
||||
char metaPath[64] = "";
|
||||
snprintf(metaPath, sizeof(metaPath), "/meta/%08x/%08x/title.met", NANDTitleIdHi(titleId), NANDTitleIdLo(titleId));
|
||||
return NANDPrivateDelete(metaPath);
|
||||
}
|
||||
|
||||
BOOL checkForNullTermination(char* str, u32 len) {
|
||||
for (u32 i = 0; i < len; i++) {
|
||||
if (*str == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
TMDFile::TMDFile(EGG::Heap* heap) : mpHeap(heap), mbFileOpen(FALSE), mFileLength(0) {
|
||||
memset(&mFile, 0, sizeof(mFile));
|
||||
}
|
||||
|
||||
s32 TMDFile::Open(char* fileName) {
|
||||
s32 ret;
|
||||
|
||||
if (mbFileOpen) {
|
||||
return NAND_RESULT_OK;
|
||||
}
|
||||
|
||||
ret = NANDPrivateOpen(fileName, &mFile, NAND_ACCESS_RW);
|
||||
if (ret == NAND_RESULT_NOEXISTS) {
|
||||
ret = NANDPrivateCreate(fileName, NAND_PERM_ALL_RW, 0);
|
||||
if (ret != NAND_RESULT_OK) {
|
||||
ES_ERR_REPORT("NANDCreate %s err: %d", fileName, ret);
|
||||
return ret;
|
||||
}
|
||||
ret = NANDPrivateOpen(fileName, &mFile, NAND_ACCESS_RW);
|
||||
}
|
||||
|
||||
if (ret != NAND_RESULT_OK) {
|
||||
ES_ERR_REPORT("NANDOpen %s err: %d", fileName, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
mbFileOpen = TRUE;
|
||||
ret = NANDGetLength(&mFile, &mFileLength);
|
||||
if (ret != NAND_RESULT_OK) {
|
||||
ES_ERR_REPORT("NANDGetLength %s err: %d", fileName, ret);
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 TMDFile::Close() {
|
||||
s32 ret = ES_ERR_OK;
|
||||
if (mbFileOpen) {
|
||||
ret = NANDClose(&mFile);
|
||||
mbFileOpen = FALSE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL TMDFile::Exist(ESTitleId titleId, u32* tmdOffset, u32* tmdSize) {
|
||||
u32 offset = 0;
|
||||
EntryHead entry ALIGN32;
|
||||
|
||||
if (!mbFileOpen) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (; offset < mFileLength; offset += OSRoundUp32B(entry.tmdSize)) {
|
||||
s32 ret = NANDSeek(&mFile, offset, NAND_SEEK_BEG);
|
||||
if (ret != offset) {
|
||||
ES_ERR_REPORT("NANDSeek err: %d!=%d", ret, offset);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
u32 readSize = NANDRead(&mFile, &entry, OSRoundUp32B(sizeof(EntryHead)));
|
||||
if (readSize != OSRoundUp32B(sizeof(EntryHead))) {
|
||||
ES_ERR_REPORT("NANDRead err: %d!=%d", readSize, OSRoundUp32B(sizeof(EntryHead)));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
offset += OSRoundUp32B(sizeof(EntryHead));
|
||||
if (entry.titleId == titleId) {
|
||||
if (tmdOffset) {
|
||||
*tmdOffset = offset;
|
||||
}
|
||||
if (tmdSize) {
|
||||
*tmdSize = entry.tmdSize;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
s32 TMDFile::Backup(ESTitleId titleId) {
|
||||
s32 ret = NAND_RESULT_OK;
|
||||
u32 entryLen;
|
||||
EntryHead* entry = NULL;
|
||||
|
||||
if (!mbFileOpen) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
u32 fileLen;
|
||||
u32 tmdSize;
|
||||
|
||||
// Is the TMD already in the backup database?
|
||||
if (!Exist(titleId, NULL, NULL)) {
|
||||
// If not, let's back you up!
|
||||
|
||||
// Get file length. (...without NANDGetLength?)
|
||||
ret = NANDSeek(&mFile, 0, NAND_SEEK_END);
|
||||
if (ret != mFileLength) {
|
||||
ES_ERR_REPORT("NANDSeek err: %d!=%d", ret, mFileLength);
|
||||
goto out;
|
||||
}
|
||||
ret = NANDTell(&mFile, &fileLen);
|
||||
if (ret != NAND_RESULT_OK) {
|
||||
ES_ERR_REPORT("NANDTell err: %d", ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
// Verify the file length.
|
||||
if (fileLen != mFileLength || (fileLen & 31)) {
|
||||
ES_ERR_REPORT("Internal error: %d!=%d || 0x%x not 32B", fileLen, mFileLength, fileLen);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
// The title metadata
|
||||
ret = ES_GetTmd(titleId, NULL, &tmdSize);
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_GetTmd err: %d", ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
// Prepare TMD backup entry.
|
||||
entryLen = OSRoundUp32B(tmdSize) + OSRoundUp32B(sizeof(EntryHead));
|
||||
entry = (EntryHead*)mpHeap->alloc(entryLen, -DEFAULT_ALIGN);
|
||||
memset(entry, 0, entryLen);
|
||||
entry->titleId = titleId;
|
||||
entry->tmdSize = tmdSize;
|
||||
|
||||
// Export TMD contents to entry
|
||||
ret = ES_ExportTitleInit(titleId, 0, 0, NULL, 0, NULL, 0, 2, NULL, entry->getTmdPtr(), tmdSize);
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_ExportTitleInit err: %d", ret);
|
||||
ES_ExportTitleDone();
|
||||
goto out;
|
||||
}
|
||||
ret = ES_ExportTitleDone();
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_ExportTitleDone err: %d", ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
// Write the entry to the backup file
|
||||
ret = NANDWrite(&mFile, entry, entryLen);
|
||||
if (ret != entryLen) {
|
||||
ES_ERR_REPORT("NANDWrite err: %d!=%d", ret, entryLen);
|
||||
goto out;
|
||||
}
|
||||
|
||||
// We are done!!!
|
||||
ret = NAND_RESULT_OK;
|
||||
mFileLength += entryLen;
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
if (entry != NULL) {
|
||||
mpHeap->free(entry);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 TMDFile::Restore(ESTitleId titleId) {
|
||||
s32 ret = NAND_RESULT_OK;
|
||||
|
||||
u32 fileLen;
|
||||
u32 tmdOffset = 0;
|
||||
u32 tmdSize = 0;
|
||||
void* tmdBuffer = NULL;
|
||||
|
||||
if (!mbFileOpen) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ES_GetTmdView(titleId, NULL, &tmdSize);
|
||||
|
||||
if (ret != ES_ERR_OK) {
|
||||
if (ret != ES_ERR_DONT_EXISTS) {
|
||||
ES_ERR_REPORT("ES_GetTmdView err: %d", ret);
|
||||
goto out;
|
||||
}
|
||||
tmdSize = 0;
|
||||
|
||||
ret = Exist(titleId, &tmdOffset, &tmdSize);
|
||||
if (ret == FALSE) {
|
||||
ret = ES_ERR_NO_TMD_FILE_FOUND;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = NANDSeek(&mFile, tmdOffset, NAND_SEEK_BEG);
|
||||
if (ret != tmdOffset) {
|
||||
ES_ERR_REPORT("NANDSeek err: %d!=%d", ret, tmdOffset);
|
||||
goto out;
|
||||
}
|
||||
|
||||
fileLen = OSRoundUp32B(tmdSize);
|
||||
tmdBuffer = mpHeap->alloc(fileLen, -DEFAULT_ALIGN);
|
||||
memset(tmdBuffer, 0, fileLen);
|
||||
|
||||
ret = NANDRead(&mFile, tmdBuffer, fileLen);
|
||||
if (ret != fileLen) {
|
||||
ES_ERR_REPORT("NANDRead err: %d!=%d", ret, fileLen);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = ES_ImportTitleInit(tmdBuffer, tmdSize, NULL, 0, NULL, 0, 2, 1);
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_ImportTitleInit err: %d", ret);
|
||||
ES_ImportTitleCancel();
|
||||
}
|
||||
|
||||
ret = ES_ImportTitleDone();
|
||||
if (ret != ES_ERR_OK) {
|
||||
ES_ERR_REPORT("ES_ImportTitleDone err: %d", ret);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
out:
|
||||
if (tmdBuffer != NULL) {
|
||||
mpHeap->free(tmdBuffer);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // namespace utility
|
||||
} // namespace ipl
|
||||
49
tools/decomp-assist/pool_diff.py
Normal file
49
tools/decomp-assist/pool_diff.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import sys
|
||||
from elftools.elf.elffile import ELFFile
|
||||
|
||||
MINE = 'build/43U/src/src/utility/iplESMisc.o'
|
||||
BASE = 'build/43U/obj/src/utility/iplESMisc.o'
|
||||
|
||||
|
||||
def pool(path):
|
||||
e = ELFFile(open(path, 'rb'))
|
||||
sec = {s.name: s for s in e.iter_sections()}
|
||||
d = sec['.data'].data()
|
||||
out = []
|
||||
off = 0
|
||||
while off < len(d):
|
||||
end = d.find(b'\x00', off)
|
||||
if end < 0:
|
||||
break
|
||||
s = d[off:end]
|
||||
if len(s) >= 4 and all(32 <= c < 127 or c == 0x0a for c in s):
|
||||
out.append((off, s.decode('latin1')))
|
||||
off = end + 1
|
||||
return out
|
||||
|
||||
|
||||
def main():
|
||||
mine = pool(sys.argv[1] if len(sys.argv) > 1 else MINE)
|
||||
base = pool(sys.argv[2] if len(sys.argv) > 2 else BASE)
|
||||
n = min(len(mine), len(base))
|
||||
for i in range(n):
|
||||
if mine[i][1] != base[i][1]:
|
||||
print('FIRST DIVERGENCE at index %d' % i)
|
||||
for j in range(max(0, i - 2), min(n, i + 5)):
|
||||
mark = '*' if mine[j][1] != base[j][1] else ' '
|
||||
print('%s %3d mine=%-8s base=%-8s' % (mark, j, hex(mine[j][0]), hex(base[j][0])))
|
||||
print(' M %r' % mine[j][1][:70])
|
||||
print(' B %r' % base[j][1][:70])
|
||||
print()
|
||||
print('mine has %d strings, base has %d' % (len(mine), len(base)))
|
||||
return 1
|
||||
print('POOL IDENTICAL up to %d (mine=%d base=%d)' % (n, len(mine), len(base)))
|
||||
if len(mine) != len(base):
|
||||
for j in range(n, max(len(mine), len(base))):
|
||||
src = mine if j < len(mine) else base
|
||||
print(' extra %3d %r' % (j, src[j][1][:70]))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user