Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
1.7.4a更新,移除seh异常,修复崩服问题,移除global.h/cpp,新增Global模板类。
Browse files Browse the repository at this point in the history
  • Loading branch information
twoone3l committed Aug 22, 2021
1 parent 9f6538c commit eda5ae5
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 132 deletions.
4 changes: 1 addition & 3 deletions BDSpyrunner/BDSpyrunner.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>$(SolutionDir)BDSpyrunner\Header File;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling>Async</ExceptionHandling>
<ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -160,7 +160,6 @@
<ClCompile Include="Source File\mod.cpp" />
<ClCompile Include="Source File\PyEntity.cpp" />
<ClCompile Include="Source File\tool.cpp" />
<ClCompile Include="Source File\global.cpp" />
</ItemGroup>
<ItemGroup>
<Library Include="Library File\chakra.lib" />
Expand All @@ -178,7 +177,6 @@
<ClInclude Include="Header File\Structure.h" />
<ClInclude Include="Header File\Tag.h" />
<ClInclude Include="Header File\Event.h" />
<ClInclude Include="Header File\global.h" />
<ClInclude Include="Header File\json.hpp" />
<ClInclude Include="Header File\PyEntity.h" />
<ClInclude Include="Header File\tool.h" />
Expand Down
6 changes: 0 additions & 6 deletions BDSpyrunner/BDSpyrunner.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<ClCompile Include="Source File\Block.cpp">
<Filter>Source File</Filter>
</ClCompile>
<ClCompile Include="Source File\global.cpp">
<Filter>Source File</Filter>
</ClCompile>
<ClCompile Include="Source File\ItemStack.cpp">
<Filter>Source File</Filter>
</ClCompile>
Expand Down Expand Up @@ -80,9 +77,6 @@
<ClInclude Include="Header File\Event.h">
<Filter>Header File</Filter>
</ClInclude>
<ClInclude Include="Header File\global.h">
<Filter>Header File</Filter>
</ClInclude>
<ClInclude Include="Header File\json.hpp">
<Filter>Header File</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions BDSpyrunner/Header File/Level.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct Scoreboard;
struct BlockPalette;
struct ItemActor;
struct ItemStack;
struct SPSCQueue;
struct Spawner {
ItemActor* spawnItem(BlockSource* bs, ItemStack* item, Vec3* pos);
};
Expand Down
1 change: 1 addition & 0 deletions BDSpyrunner/Header File/PyEntity.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <string>
#define PY_SSIZE_T_CLEAN
#include "include/Python.h"

#define Py_RETURN_ERROR(str) return PyErr_SetString(PyExc_Exception, str), nullptr
Expand Down
11 changes: 0 additions & 11 deletions BDSpyrunner/Header File/global.h

This file was deleted.

16 changes: 12 additions & 4 deletions BDSpyrunner/Header File/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#pragma execution_character_set("utf-8")
#include <iostream>

#define SEH_BEGIN try {
#define SEH_END } catch (...) { cerr << "SEH exception was occured in file " __FILE__ ", funtion " __FUNCTION__ ", line " << __LINE__ << endl; }
#define FETCH(type, ptr) (*reinterpret_cast<type*>(ptr))
#define SYM GetServerSymbol
#define HOOK(name, ret, sym, ...) \
Expand All @@ -12,8 +10,7 @@ struct name { \
static func _hook; \
static func* original; \
}; \
name::func* name::original = \
*reinterpret_cast<name::func**>(SymHook(sym, name::_hook, &name::original));\
name::func* name::original = *reinterpret_cast<name::func**>(SymHook(sym, name::_hook, &name::original));\
ret name::_hook(__VA_ARGS__)
extern "C" {
// provide Detours API
Expand All @@ -37,6 +34,17 @@ ReturnType SymCall(const char* sym, Args... args) {
}
// replace the function
void* SymHook(const char* sym, void* hook, void* org);
//È«¾Ö±äÁ¿
template <typename T>
struct Global {
static T* data;
};
//Global<SPSCQueue>::data = nullptr;
//Global<RakPeer>::data = nullptr;
//Global<ServerNetworkHandler>::data = nullptr;
//Global<Level>::data = nullptr;
//Global<>::data = nullptr;

constexpr size_t Hash(const char* s);
//´´½¨°ü
uintptr_t createPacket(int type);
Expand Down
4 changes: 2 additions & 2 deletions BDSpyrunner/Source File/Actor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <Actor.h>
#include <NetWork.h>
#include <Tag.h>
#include <ItemStack.h>
#include <global.h>
#include <ScoreBoard.h>

using namespace std;
Expand Down Expand Up @@ -386,7 +386,7 @@ void Player::sendCommandRequestPacket(const string& cmd) {
uintptr_t pkt = createPacket(77);
FETCH(string, pkt + 48) = cmd;
SymCall<uintptr_t>("?handle@ServerNetworkHandler@@UEAAXAEBVNetworkIdentifier@@AEBVCommandRequestPacket@@@Z",
g_server_network_handler, getClientId(), pkt);
Global<ServerNetworkHandler>::data, getClientId(), pkt);
//p->sendPacket(pkt);
}

Expand Down
13 changes: 6 additions & 7 deletions BDSpyrunner/Source File/PyEntity.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <PyEntity.h>
#include <tool.h>
#include <global.h>
#include <Actor.h>
#include <Tag.h>
#include <ItemStack.h>
Expand Down Expand Up @@ -256,7 +255,7 @@ PyObject* PyEntity_GetIP(PyObject* self, void*) {
Player* p = PyEntity_AsPlayer(self);
if (!p)
return nullptr;
return ToPyUnicode(g_rak_peer->getSystemAddress(p->getClientId()).toString());
return ToPyUnicode(Global<RakPeer>::data->getSystemAddress(p->getClientId()).toString());
}

//获取/设置玩家所有物品
Expand Down Expand Up @@ -429,9 +428,9 @@ PyObject* PyEntity_GetScore(PyObject* self, PyObject* args) {
Player* p = PyEntity_AsPlayer(self);
if (!p)
return nullptr;
Objective* testobj = g_scoreboard->getObjective(objname);
Objective* testobj = Global<Scoreboard>::data->getObjective(objname);
if (testobj) {
auto id = g_scoreboard->getScoreboardId(p);
auto id = Global<Scoreboard>::data->getScoreboardId(p);
auto score = testobj->getPlayerScore(id);
return PyLong_FromLong(score->getCount());
}
Expand All @@ -445,10 +444,10 @@ PyObject* PyEntity_ModifyScore(PyObject* self, PyObject* args) {
Player* p = PyEntity_AsPlayer(self);
if (!p)
return nullptr;
Objective* testobj = g_scoreboard->getObjective(objname);
Objective* testobj = Global<Scoreboard>::data->getObjective(objname);
if (testobj) {
//mode:{set,add,remove}
g_scoreboard->modifyPlayerScore((ScoreboardId*)g_scoreboard->getScoreboardId(p), testobj, count, mode);
Global<Scoreboard>::data->modifyPlayerScore(Global<Scoreboard>::data->getScoreboardId(p), testobj, count, mode);
}
}
Py_RETURN_NONE;
Expand Down Expand Up @@ -535,7 +534,7 @@ PyObject* PyEntity_SetSidebar(PyObject* self, PyObject* args) {
vector<ScorePacketInfo> info;
if (value.is_object())
for (auto& [key, val] : value.items()) {
ScorePacketInfo o(g_scoreboard->createScoreBoardId(key),
ScorePacketInfo o(Global<Scoreboard>::data->createScoreBoardId(key),
val.get<int>(), key);
info.push_back(o);
}
Expand Down
12 changes: 0 additions & 12 deletions BDSpyrunner/Source File/global.cpp

This file was deleted.

Loading

0 comments on commit eda5ae5

Please sign in to comment.