Skip to content

Commit 4517151

Browse files
committed
feat: add raccoon requests parser
1 parent 4dd6861 commit 4517151

File tree

6 files changed

+657
-2
lines changed

6 files changed

+657
-2
lines changed

apps/stardew.app/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@types/node": "20.4.0",
4646
"@types/react": "18.2.14",
4747
"@types/react-dom": "18.2.6",
48+
"@types/xxhashjs": "^0.2.4",
4849
"autoprefixer": "10.4.14",
4950
"axios": "^1.7.2",
5051
"class-variance-authority": "^0.6.1",
@@ -72,6 +73,7 @@
7273
"tailwindcss-animate": "^1.0.6",
7374
"typescript": "5.1.6",
7475
"vaul": "^0.8.0",
76+
"xxhashjs": "^0.2.2",
7577
"zod": "^3.23.8"
7678
},
7779
"devDependencies": {
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
{
2+
"first": [
3+
{
4+
"item": ["722", "721", "716", "719", "723", "718", "372"],
5+
"quantity": 5
6+
},
7+
{
8+
"item": [
9+
["136", "132", "700", "702", "156", "267", "706"],
10+
[
11+
"136",
12+
"132",
13+
"700",
14+
"702",
15+
"156",
16+
"267",
17+
"706",
18+
"138",
19+
"701",
20+
"146",
21+
"130"
22+
],
23+
["136", "132", "700", "702", "156", "701", "269", "139", "139"],
24+
["136", "132", "700", "702", "156", "146", "130", "141", "269"]
25+
],
26+
"quantity": 1
27+
},
28+
{
29+
"reward": [
30+
"CarrotSeeds",
31+
"SummerSquashSeeds",
32+
"BroccoliSeeds",
33+
"PowdermelonSeeds"
34+
],
35+
"quantity": 25
36+
}
37+
],
38+
"second": [
39+
{
40+
"item": [
41+
["90", "634", "638", "400", "88"],
42+
["90", "258", "260", "635", "636", "88", "396"],
43+
["90", "613", "282", "637", "410", "88", "406"],
44+
["90", "414", "414", "88", "Powdermelon", "Powdermelon"]
45+
],
46+
"quantity": 1
47+
},
48+
{
49+
"reward": ["Book_WildSeeds"],
50+
"quantity": 1
51+
}
52+
],
53+
"third": [
54+
{
55+
"item": [
56+
["422", "404", "257"],
57+
["422", "404"],
58+
["422", "404", "281"],
59+
["422", "404"]
60+
],
61+
"quantity": 1
62+
},
63+
{
64+
"item": ["Any Egg (excluding Dinosaur)", "78", "157"],
65+
"quantity": 5
66+
},
67+
{
68+
"reward": ["Raccoon Hat"],
69+
"quantity": 1
70+
}
71+
],
72+
"fourth": [
73+
{
74+
"item": [
75+
["190", "188", "250", "192", "16", "22", "Carrot", "Carrot"],
76+
["270", "264", "256", "78", "SummerSquash", "SummerSquash"],
77+
["Broccoli", "Broccoli", "278", "272", "276"],
78+
["416", "412", "78"]
79+
],
80+
"quantity": 1
81+
},
82+
{
83+
"reward": ["872"],
84+
"quantity": 5
85+
}
86+
],
87+
"fifth": [
88+
{
89+
"item": ["Moss"],
90+
"quantity": 10
91+
},
92+
{
93+
"item": ["110"],
94+
"quantity": 1
95+
},
96+
{
97+
"item": ["168"],
98+
"quantity": 5
99+
},
100+
{
101+
"item": ["766"],
102+
"quantity": 99
103+
},
104+
{
105+
"item": ["767"],
106+
"quantity": 20
107+
},
108+
{
109+
"item": ["535"],
110+
"quantity": 8
111+
},
112+
{
113+
"item": ["536"],
114+
"quantity": 5
115+
},
116+
{
117+
"item": ["537"],
118+
"quantity": 3
119+
},
120+
{
121+
"item": ["393"],
122+
"quantity": 4
123+
},
124+
{
125+
"item": ["397"],
126+
"quantity": 2
127+
},
128+
{
129+
"item": ["684"],
130+
"quantity": 20
131+
},
132+
{
133+
"item": ["72"],
134+
"quantity": 1
135+
},
136+
{
137+
"item": ["68"],
138+
"quantity": 3
139+
},
140+
{
141+
"item": ["156"],
142+
"quantity": 3
143+
},
144+
{
145+
"reward": ["Jungle Tank"],
146+
"quantity": 1
147+
}
148+
],
149+
"randomRewards": [
150+
{
151+
"reward": ["872"],
152+
"quantity": 7
153+
},
154+
{
155+
"reward": ["PurpleBook"],
156+
"quantity": 1
157+
},
158+
{
159+
"reward": ["Next unshipped item (other than Roe and Artisan Goods)"],
160+
"quantity": 1,
161+
"fallback": { "reward": ["MysteryBox"], "quantity": 5 }
162+
},
163+
{
164+
"reward": ["StardropTea"],
165+
"quantity": 1
166+
},
167+
{
168+
"reward": [
169+
"CarrotSeeds",
170+
"SummerSquashSeeds",
171+
"BroccoliSeeds",
172+
"PowdermelonSeeds"
173+
],
174+
"quantity": 25
175+
}
176+
]
177+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/* cs-random.js from mouseypounds' predictor
2+
Simple and incomplete Javascript implementation of the C# pseudo random number generator
3+
published at http://referencesource.microsoft.com/#mscorlib/system/random.cs */
4+
5+
const INT_MIN = -2147483648;
6+
const INT_MAX = 2147483647;
7+
const MBIG = INT_MAX;
8+
const MSEED = 161803398;
9+
10+
function CSRandom(Seed) {
11+
"use strict";
12+
let ii, mj, mk, i, k, subtraction;
13+
14+
// Alternative to default argument
15+
if (typeof Seed === "undefined") {
16+
Seed = Date.getTime();
17+
}
18+
Seed = Math.imul(1, parseInt(Seed)); // Force a 32-bit integer since there is no type checking
19+
20+
this.inext = 0;
21+
this.inextp = 0;
22+
this.SeedArray = [];
23+
24+
subtraction = Seed === INT_MIN ? INT_MAX : Math.abs(Seed);
25+
mj = MSEED - subtraction;
26+
this.SeedArray[55] = mj;
27+
mk = 1;
28+
for (let i = 1; i < 55; i++) {
29+
ii = (21 * i) % 55;
30+
this.SeedArray[ii] = mk;
31+
mk = mj - mk;
32+
if (mk < 0) {
33+
mk += MBIG;
34+
}
35+
mj = this.SeedArray[ii];
36+
}
37+
for (let k = 1; k < 5; k++) {
38+
for (i = 1; i < 56; i++) {
39+
this.SeedArray[i] -= this.SeedArray[1 + ((i + 30) % 55)];
40+
if (this.SeedArray[i] > INT_MAX) {
41+
this.SeedArray[i] -= 4294967296;
42+
} else if (this.SeedArray[i] < INT_MIN) {
43+
this.SeedArray[i] += 4294967296;
44+
}
45+
if (this.SeedArray[i] < 0) {
46+
this.SeedArray[i] += MBIG;
47+
}
48+
}
49+
}
50+
this.inext = 0;
51+
this.inextp = 21;
52+
Seed = 1;
53+
}
54+
55+
CSRandom.prototype.Sample = function () {
56+
"use strict";
57+
return parseFloat(this.InternalSample() * (1.0 / MBIG));
58+
};
59+
60+
CSRandom.prototype.InternalSample = function () {
61+
"use strict";
62+
let retVal;
63+
let locINext = this.inext;
64+
let locINextp = this.inextp;
65+
66+
if (++locINext >= 56) {
67+
locINext = 1;
68+
}
69+
if (++locINextp >= 56) {
70+
locINextp = 1;
71+
}
72+
retVal = this.SeedArray[locINext] - this.SeedArray[locINextp];
73+
if (retVal === MBIG) {
74+
retVal--;
75+
}
76+
if (retVal < 0) {
77+
retVal += MBIG;
78+
}
79+
this.SeedArray[locINext] = retVal;
80+
this.inext = locINext;
81+
this.inextp = locINextp;
82+
return parseInt(retVal);
83+
};
84+
85+
CSRandom.prototype.GetSampleForLargeRange = function () {
86+
"use strict";
87+
// This might require special large integer handling
88+
let result = this.InternalSample(),
89+
d;
90+
91+
if (this.InternalSample() % 2 === 0) {
92+
result = -result;
93+
}
94+
d = result;
95+
d += INT_MAX - 1;
96+
d /= 2 * INT_MAX - 1;
97+
return d;
98+
};
99+
100+
CSRandom.prototype.Next = function (a, b) {
101+
"use strict";
102+
// Next() gives range of [0..INT_MAX)
103+
// Next(a) gives range of [0..a)
104+
// Next(a,b) gives range of [a..b)
105+
let min = 0;
106+
let max = INT_MAX;
107+
let range;
108+
109+
if (typeof b !== "undefined") {
110+
// 2 parameter version
111+
max = b;
112+
min = typeof a !== "undefined" ? a : 0;
113+
if (min > max) {
114+
throw (
115+
"Argument out of range - min (" +
116+
min +
117+
") should be smaller than max (" +
118+
max +
119+
")"
120+
);
121+
}
122+
range = max - min;
123+
if (range <= INT_MAX) {
124+
return Math.floor(this.Sample() * range) + min;
125+
} else {
126+
return Math.floor(this.GetSampleForLargeRange() * range) + min;
127+
}
128+
} else if (typeof a !== "undefined") {
129+
// 1 parameter version
130+
max = a;
131+
if (max < 0) {
132+
throw "Argument out of range - max (" + max + ") must be positive";
133+
}
134+
return Math.floor(this.Sample() * max);
135+
} else {
136+
return this.InternalSample();
137+
}
138+
};
139+
140+
export { CSRandom };

apps/stardew.app/src/lib/file.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { GetListOrEmpty, getAllFarmhands } from "@/lib/utils";
1919
import { parseAnimals } from "./parsers/animals";
2020
import { parseNotes } from "./parsers/notes";
21+
import { parseRaccoon } from "./parsers/raccoon";
2122
import { parseScraps } from "./parsers/scraps";
2223
import { parseWalnuts } from "./parsers/walnuts";
2324

@@ -123,6 +124,12 @@ export function parseSaveFile(xml: string) {
123124
prefix,
124125
);
125126

127+
const parsedRaccoon = parseRaccoon(
128+
saveFile.SaveGame.useLegacyRandom,
129+
saveFile.SaveGame.uniqueIDForThisGame,
130+
saveFile.SaveGame.timesFedRaccoons,
131+
);
132+
126133
players.forEach((player) => {
127134
// in here is where we'll call all our parsers and create the player object we'll use
128135
let processedPlayer = {
@@ -164,12 +171,11 @@ export function parseSaveFile(xml: string) {
164171
...parsedAnimals,
165172
horse: player.horseName,
166173
},
174+
raccoon: parsedRaccoon,
167175
};
168176
processedPlayers.push(processedPlayer);
169177
});
170178

171-
console.log("processedPlayers", processedPlayers);
172-
173179
// processedPlayers.forEach((p) =>
174180
// console.log(`Player: ${p.general.name} | powers:`, p.powers.collection),
175181
// );

0 commit comments

Comments
 (0)