chore: archive early implementations and chunk checker tools
This commit is contained in:
parent
7a06f94577
commit
69f7f7a34b
9 changed files with 1408 additions and 0 deletions
9
tools/Makefile
Normal file
9
tools/Makefile
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
CXX ?= g++
|
||||
CXXFLAGS ?= -O3 -std=c++17 -fwrapv
|
||||
.PHONY: all clean
|
||||
all: bin/sliming
|
||||
bin/sliming: sliming.cpp
|
||||
mkdir -p bin
|
||||
$(CXX) $(CXXFLAGS) $< -o $@
|
||||
clean:
|
||||
rm -f bin/sliming
|
||||
10
tools/README.md
Normal file
10
tools/README.md
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# 小工具与历史参考
|
||||
|
||||
`sliming.cpp` 是从根目录归档过来的单区块 Java 随机数检查工具,算法未改动。
|
||||
|
||||
```sh
|
||||
make tools
|
||||
./tools/bin/sliming 61692151016558 51069 419124
|
||||
```
|
||||
|
||||
`reference/sliming.s` 保留先前的汇编快照,供研究编译器输出时参考;它不是从当前源码重新生成的产物,不参与构建。原根目录的旧 `sliming` 可执行文件已被忽略,可通过 `make clean` 清理。
|
||||
73
tools/reference/sliming.s
Normal file
73
tools/reference/sliming.s
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
.file "sliming.cpp"
|
||||
.text
|
||||
.p2align 4
|
||||
.globl _Z12isSlimeChunklii
|
||||
.type _Z12isSlimeChunklii, @function
|
||||
_Z12isSlimeChunklii:
|
||||
.LFB7:
|
||||
.cfi_startproc
|
||||
endbr64
|
||||
movl %esi, %eax
|
||||
movl %edx, %ecx
|
||||
imull %esi, %eax
|
||||
imull %edx, %ecx
|
||||
imull $5947611, %esi, %esi
|
||||
imull $4987142, %eax, %eax
|
||||
movslq %ecx, %rcx
|
||||
imull $389711, %edx, %edx
|
||||
imulq $4392871, %rcx, %rcx
|
||||
movslq %esi, %rsi
|
||||
cltq
|
||||
addq %rdi, %rax
|
||||
movslq %edx, %rdx
|
||||
addq %rsi, %rax
|
||||
addq %rcx, %rax
|
||||
addq %rdx, %rax
|
||||
movabsq $25303508018, %rdx
|
||||
xorq %rdx, %rax
|
||||
movabsq $281474976710655, %rdx
|
||||
andq %rdx, %rax
|
||||
movabsq $25214903917, %rdx
|
||||
imulq %rdx, %rax
|
||||
addq $11, %rax
|
||||
shrq $17, %rax
|
||||
andl $2147483647, %eax
|
||||
imull $-858993459, %eax, %eax
|
||||
rorl %eax
|
||||
cmpl $429496729, %eax
|
||||
setbe %al
|
||||
ret
|
||||
.cfi_endproc
|
||||
.LFE7:
|
||||
.size _Z12isSlimeChunklii, .-_Z12isSlimeChunklii
|
||||
.section .text.startup,"ax",@progbits
|
||||
.p2align 4
|
||||
.globl main
|
||||
.type main, @function
|
||||
main:
|
||||
.LFB8:
|
||||
.cfi_startproc
|
||||
endbr64
|
||||
xorl %eax, %eax
|
||||
ret
|
||||
.cfi_endproc
|
||||
.LFE8:
|
||||
.size main, .-main
|
||||
.ident "GCC: (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0"
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
.section .note.gnu.property,"a"
|
||||
.align 8
|
||||
.long 1f - 0f
|
||||
.long 4f - 1f
|
||||
.long 5
|
||||
0:
|
||||
.string "GNU"
|
||||
1:
|
||||
.align 8
|
||||
.long 0xc0000002
|
||||
.long 3f - 2f
|
||||
2:
|
||||
.long 0x3
|
||||
3:
|
||||
.align 8
|
||||
4:
|
||||
53
tools/sliming.cpp
Normal file
53
tools/sliming.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#pragma GCC optimize("wrapv")
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct JavaRandom {
|
||||
int64_t seed;
|
||||
|
||||
JavaRandom(int64_t seed) : seed((seed ^ 0x5DEECE66DLL) & ((1LL << 48) - 1)) {}
|
||||
|
||||
int32_t next(int bits) {
|
||||
seed = (seed * 0x5DEECE66DLL + 0xBLL) & ((1LL << 48) - 1);
|
||||
return (int32_t)((uint64_t)seed >> (48 - bits));
|
||||
}
|
||||
|
||||
int32_t nextInt(int32_t n) {
|
||||
if ((n & -n) == n) // n is a power of 2
|
||||
return (int32_t)((n * (int64_t)next(31)) >> 31);
|
||||
|
||||
int32_t bits, val;
|
||||
do {
|
||||
bits = next(31);
|
||||
val = bits % n;
|
||||
} while (bits - val + (n - 1) < 0);
|
||||
return val;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
bool isSlimeChunk(int64_t worldSeed, int32_t chunkX, int32_t chunkZ) {
|
||||
int64_t seed = worldSeed +
|
||||
(int64_t)(chunkX * chunkX * 4987142) +
|
||||
(int64_t)(chunkX * 5947611) +
|
||||
(int64_t)(chunkZ * chunkZ) * 4392871LL +
|
||||
(int64_t)(chunkZ * 389711) ^ 987234911LL;
|
||||
JavaRandom rand(seed);
|
||||
return rand.nextInt(10) == 0;
|
||||
}
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 4) {
|
||||
return 1;
|
||||
}
|
||||
int64_t worldSeed = atoll(argv[1]);
|
||||
int32_t chunkX = atoi(argv[2]);
|
||||
int32_t chunkZ = atoi(argv[3]);
|
||||
bool isSlime = isSlimeChunk(worldSeed, chunkX, chunkZ);
|
||||
printf("Is Slime Chunk: %s\n", isSlime ? "true" : "false");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue