samyyc.dev
LOC::Macau, China

..UTC+8

samyyc.dev

-- BPM

Sun Jan 21 2024

Changing Dinosaur Spawn Chances in the Jurassic World Rebirth MOD

#96

/

samyyc

/

446 words

/

Updated 1048 days ago

/

[中文]

Changing Dinosaur Spawn Chances in the Jurassic World Rebirth MOD

Development on the mod is slow, and it doesn't provide a config file for adjusting dinosaur spawn rates. If you want to change it quickly, the only way is to modify the source code. Since this mod is an unofficial Chinese localization, there are many different versions, and directly modifying the official source and compiling it isn't really feasible either. (Too much hassle.) So the only option is to decompile it and brute-force the changes.

Recaf

I've always liked using Recaf for modifying jar source code, so I'll use it as an example here.

Analyzing the source

By looking at the dinosaur base class reborn.server.dinosaur.Dinasour, you can see that the different dinosaur classes all have two properties: spawnChance and maxHerdSize. Spawning is mainly controlled by these two values.

29E2B67B-A198-4381-B6B7-6433F3C98C4E.pngspawnChance controls the spawn probability, and maxHerdSize controls the maximum spawn count.

Modifying the values with Recaf

You can either modify the values for a single dinosaur or directly modify all of them in the Dinosaur class. The method is pretty much the same, so I'll just modify the Dinosaur base class here as a demo.

First open Recaf, import the mod's jar, and find reborn.server.dinosaur.

8A33E149-1E67-493D-AB3C-8FC3ED91D8E4.png

Then find the Dinosaur base class below (if you're modifying a single dinosaur, modify the dinosaur class you want):

BCDEAEBB-CB68-41A8-A9DD-ABD68978E4E7.png

Find the getSpawnChance() method.

7A64390D-07E0-4455-892A-6D403F97C341.png

Right-click the method name, select Edit with Assembler, and you'll see the following window:

5A3FC93D-3565-4573-84C1-C26994C0F970.png Delete the GETFIELD line and replace it with the bytecode for the value you want.

Generally, this is a probability, so enter a value from 1 to 100.

The bytecode rules are as follows:

  • For values from -1 to 5, use ICONST (e.g., -1 is ICONST_M1, 5 is ICONST_5)
  • For values from -128 to 127, use BIPUSH (e.g., BIPUSH 80)
  • For values from -32768 to 32767, use SIPUSH (e.g., SIPUSH 1000)
  • For values from -2147483648 to 2147483647, use LDC

After the change it looks like this (I changed it to 80 here):

3816DC54-FDDF-4288-B064-882A2E54C213.png

After you're done, press Ctrl+S to save, and you can see the code has been modified:

BCA35AEC-BA44-4A6B-8CA0-D0A28997787C.png

If you're a bit OCD, you can also delete the ALOAD line, which gets rid of that useless definition at the front.

Then it's pretty much the same for the maxHerdSize method. Find the getMaxHerdSize method and modify it the same way as above; I won't go into detail here.

When you're done, choose File -> Export program from the top-left to export the jar; that's your modified mod

With that, the modification is done.