aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/BiomeOverrideLayer.cpp
blob: 84605740809bee6405ae8ba942532b84f380b486 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "stdafx.h"
#include "net.minecraft.world.level.biome.h"
#include "net.minecraft.world.level.newbiome.layer.h"
#include "net.minecraft.world.level.h"
#include "BiomeOverrideLayer.h"


BiomeOverrideLayer::BiomeOverrideLayer(int seedMixup) : Layer(seedMixup)
{
	m_biomeOverride = byteArray( width * height );

#ifdef _UNICODE
	wstring path = L"GAME:\\GameRules\\biomemap.bin";
	HANDLE file = CreateFile(path.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
#else
#ifdef _WINDOWS64
	string path = "GameRules\\biomemap.bin";
#else
	string path = "GAME:\\GameRules\\biomemap.bin";
#endif
	HANDLE file = CreateFile(path.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
#endif
	if( file == INVALID_HANDLE_VALUE )
	{
		DWORD error = GetLastError();
		//assert(false);
		app.DebugPrintf("Biome override not found, using plains as default\n");

		memset(m_biomeOverride.data,Biome::plains->id,m_biomeOverride.length);
	}
	else
	{

#ifdef _DURANGO
		__debugbreak();	// TODO
		DWORD bytesRead,dwFileSize = 0;
#else
		DWORD bytesRead,dwFileSize = GetFileSize(file,nullptr);
#endif
		if(dwFileSize > m_biomeOverride.length)
		{
			app.DebugPrintf("Biomemap binary is too large!!\n");
			__debugbreak();
		}
		BOOL bSuccess = ReadFile(file,m_biomeOverride.data,dwFileSize,&bytesRead,nullptr);

		if(bSuccess==FALSE)
		{
			app.FatalLoadError();
		}

		CloseHandle(file);
	}
}

intArray BiomeOverrideLayer::getArea(int xo, int yo, int w, int h)
{
	intArray result = IntCache::allocate(w * h);

	int xOrigin = xo + width/2;
	int yOrigin = yo + height/2;
	if(xOrigin < 0 ) xOrigin = 0;
	if(xOrigin >= width) xOrigin = width - 1;
	if(yOrigin < 0 ) yOrigin = 0;
	if(yOrigin >= height) yOrigin = height - 1;
	for (int y = 0; y < h; y++)
	{
		for (int x = 0; x < w; x++)
		{
			int curX = xOrigin + x;
			int curY = yOrigin + y;
			if(curX >= width) curX = width - 1;
			if(curY >= height) curY = height - 1;
			int index = curX + curY * width;

			unsigned char headerValue = m_biomeOverride[index];
			result[x + y * w] = headerValue;
		}
	}
	return result;
}