Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 43d80d1

Browse files
committed
REVERTERINO
1 parent 9df7124 commit 43d80d1

File tree

6 files changed

+6
-259
lines changed

6 files changed

+6
-259
lines changed

byond-extools/src/core/byond_constants.h

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,9 @@ enum DataType : uint8_t
1818
WORLD_D = 0x0E,
1919
LIST = 0x0F,
2020
LIST_ARGS = 0x10,
21-
LIST_MOB_VERBS = 0x11,
2221
LIST_VERBS = 0x12,
23-
LIST_TURF_VERBS = 0x13,
24-
LIST_AREA_VERBS = 0x14,
25-
LIST_CLIENT_VERBS = 0x15,
26-
LIST_SAVEFILE_DIR = 0x16,
27-
LIST_MOB_CONTENTS = 0x17,
2822
LIST_TURF_CONTENTS = 0x18,
29-
LIST_AREA_CONTENTS = 0x19,
3023
LIST_WORLD_CONTENTS = 0x1A,
31-
LIST_GROUP = 0x1B,
3224
LIST_CONTENTS = 0x1C,
3325
DATUM_TYPEPATH = 0x20,
3426
DATUM = 0x21,
@@ -41,36 +33,8 @@ enum DataType : uint8_t
4133
NUMBER = 0x2A,
4234
LIST_MOB_VARS = 0x2C,
4335
LIST_OBJ_VARS = 0x2D,
44-
LIST_TURF_VARS = 0x2E,
45-
LIST_AREA_VARS = 0x2F,
46-
LIST_CLIENT_VARS = 0x30,
47-
LIST_VARS = 0x31, //maybe?
48-
LIST_MOB_OVERLAYS = 0x32,
49-
LIST_MOB_UNDERLAYS = 0x33,
50-
LIST_OVERLAYS = 0x34,
51-
LIST_UNDERLAYS = 0x35,
52-
LIST_TURF_OVERLAYS = 0x36,
53-
LIST_TURF_UNDERLAYS = 0x37,
54-
LIST_AREA_OVERLAYS = 0x38,
55-
LIST_AREA_UNDERLAYS = 0x39,
5636
APPEARANCE = 0x3A,
5737
CLIENT_TYPEPATH = 0x3B,
58-
IMAGE_TYPEPATH = 0x3F,
59-
LIST_IMAGE_OVERLAYS = 0x40,
60-
LIST_IMAGE_UNDERLAYS = 0x41,
61-
LIST_IMAGE_VARS = 0x42,
62-
LIST_IMAGE_VERBS = 0x43,
63-
LIST_IMAGE_CONTENTS = 0x44, // wait wtf
64-
LIST_CLIENT_IMAGES = 0x46,
65-
LIST_CLIENT_SCREEN = 0x47,
66-
LIST_TURF_VIS_CONTENTS = 0x4B,
67-
LIST_VIS_CONTENTS = 0x4C,
68-
LIST_MOB_VIS_CONTENTS = 0x4D,
69-
LIST_TURF_VIS_LOCS = 0x4E,
70-
LIST_VIS_LOCS = 0x4F,
71-
LIST_MOB_VIS_LOCS = 0x50,
72-
LIST_WORLD_VARS = 0x51,
38+
LIST_VARS = 0x31, //maybe?
7339
LIST_GLOBAL_VARS = 0x52,
74-
FILTERS = 0x53,
75-
LIST_IMAGE_VIS_CONTENTS = 0x54,
7640
};

byond-extools/src/core/byond_structures.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,6 @@ struct TableHolderThingy
516516
unsigned int* elements; //?????
517517
};
518518

519-
struct TableHolder2
520-
{
521-
void** elements;
522-
unsigned int length;
523-
};
524-
525519
struct VarListEntry;
526520

527521
struct UnknownSimpleLinkedListEntry
@@ -593,11 +587,3 @@ struct VarListEntry
593587
std::uint32_t name_id;
594588
trvh value;
595589
};
596-
597-
struct SuspendedProcList
598-
{
599-
ProcConstants** buffer;
600-
std::uint32_t front;
601-
std::uint32_t back;
602-
std::uint32_t max_elements;
603-
};

byond-extools/src/core/core.cpp

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ unsigned int* Core::datum_pointer_table_length;
1414

1515
int ByondVersion;
1616
int ByondBuild;
17-
unsigned int* Core::some_flags_including_profile;
1817
unsigned int Core::extended_profiling_insanely_hacky_check_if_its_a_new_call_or_resume;
1918

2019
//std::vector<bool> Core::codecov_executed_procs;
@@ -25,15 +24,8 @@ unsigned int next_opcode_id = 0x1337;
2524
bool Core::initialized = false;
2625
unsigned int* Core::name_table_id_ptr = nullptr;
2726
unsigned int* Core::name_table = nullptr;
28-
Value* Core::global_var_table = nullptr;
2927
std::unordered_map<std::string, Value*> Core::global_direct_cache;
3028

31-
TableHolder2* Core::obj_table = nullptr;
32-
TableHolder2* Core::datum_table = nullptr;
33-
TableHolder2* Core::list_table = nullptr;
34-
TableHolder2* Core::mob_table = nullptr;
35-
SuspendedProcList* Core::suspended_proc_list = nullptr;
36-
3729
Core::ManagedString::ManagedString(unsigned int id) : string_id(id)
3830
{
3931
string_entry = GetStringTableEntry(string_id);
@@ -118,10 +110,8 @@ void Core::Alert(int what)
118110
Alert(std::to_string(what));
119111
}
120112

121-
unsigned int Core::GetStringId(std::string str, bool increment_refcount)
122-
{
123-
if (ByondVersion > 513)
124-
{
113+
unsigned int Core::GetStringId(std::string str, bool increment_refcount) {
114+
if (ByondVersion == 514) {
125115
return GetStringTableIndexUTF8(str.c_str(), 0xFFFFFFFF, 0, 1);
126116
}
127117
return 0;
@@ -167,18 +157,6 @@ void Core::stack_push(Value val)
167157
(*Core::current_execution_context_ptr)->stack[(*Core::current_execution_context_ptr)->stack_size-1] = val;
168158
}
169159

170-
bool Core::enable_profiling()
171-
{
172-
*some_flags_including_profile |= FLAG_PROFILE;
173-
return true;
174-
}
175-
176-
bool Core::disable_profiling()
177-
{
178-
*some_flags_including_profile &= ~FLAG_PROFILE;
179-
return true;
180-
}
181-
182160
std::string Core::type_to_text(unsigned int type)
183161
{
184162
return GetStringFromId(GetTypeById(type)->path);
@@ -219,44 +197,6 @@ std::uint32_t Core::get_socket_from_client(unsigned int id)
219197
return ((Hellspawn*)(str - 0x74))->handle;
220198
}
221199

222-
Value* locate_global_by_name(std::string name)
223-
{
224-
unsigned int varname = Core::GetStringId(name);
225-
TableHolderThingy* tht = GetTableHolderThingyById(*Core::name_table_id_ptr);
226-
int id;
227-
for (id = 0; id < tht->length; id++) // add binary search here
228-
{
229-
if (Core::name_table[tht->elements[id]] == varname)
230-
{
231-
break;
232-
}
233-
}
234-
return &Core::global_var_table[tht->elements[id]];
235-
}
236-
237-
void Core::global_direct_set(std::string name, Value val)
238-
{
239-
if (auto ptr = global_direct_cache.find(name); ptr != global_direct_cache.end())
240-
{
241-
*ptr->second = val;
242-
}
243-
Value* var = locate_global_by_name(name);
244-
*var = val;
245-
global_direct_cache[name] = var;
246-
}
247-
248-
Value Core::global_direct_get(std::string name)
249-
{
250-
if (auto ptr = global_direct_cache.find(name); ptr != global_direct_cache.end())
251-
{
252-
return *ptr->second;
253-
}
254-
Value* var = locate_global_by_name(name);
255-
global_direct_cache[name] = var;
256-
return *var;
257-
}
258-
259-
260200
void Core::disconnect_client(unsigned int id)
261201
{
262202
#ifdef _WIN32

byond-extools/src/core/core.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,16 @@ namespace Core
9191
extern std::map<std::string, unsigned int> name_to_opcode;
9292
extern ExecutionContext** current_execution_context_ptr;
9393
extern MiscEntry** misc_entry_table;
94-
extern unsigned int* some_flags_including_profile;
9594
extern unsigned int* name_table_id_ptr;
9695
extern unsigned int* name_table;
97-
extern Value* global_var_table;
98-
extern TableHolder2* obj_table;
99-
extern TableHolder2* datum_table;
100-
extern TableHolder2* list_table; //list list honk
101-
extern TableHolder2* mob_table;
102-
extern SuspendedProcList* suspended_proc_list;
96+
97+
extern RawDatum*** datum_pointer_table;
98+
extern unsigned int* datum_pointer_table_length;
10399

104100
extern RawDatum*** datum_pointer_table;
105101
extern unsigned int* datum_pointer_table_length;
106102

107103
extern std::unordered_map<std::string, Value*> global_direct_cache;
108-
void global_direct_set(std::string name, Value val);
109-
Value global_direct_get(std::string name);
110104

111105

112106
//extern std::vector<bool> codecov_executed_procs;
@@ -127,8 +121,6 @@ namespace Core
127121
Value get_stack_value(unsigned int which);
128122
void stack_pop(unsigned int how_many);
129123
void stack_push(Value val);
130-
bool enable_profiling();
131-
bool disable_profiling();
132124
std::string type_to_text(unsigned int type);
133125
std::string stringify(Value val);
134126
void disconnect_client(unsigned int id);

byond-extools/src/core/core_exports.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
#include "core.h"
22

3-
extern "C" EXPORT const char* enable_profiling(int n_args, const char** args)
4-
{
5-
Core::initialize() && Core::enable_profiling();
6-
return Core::SUCCESS;
7-
}
8-
9-
extern "C" EXPORT const char* disable_profiling(int n_args, const char** args)
10-
{
11-
Core::initialize() && Core::disable_profiling();
12-
return Core::SUCCESS;
13-
}
14-
153
extern "C" EXPORT const char* core_initialize(int n_args, const char** args)
164
{
175
if (!Core::initialize())

byond-extools/src/core/various_testing.cpp

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "core.h"
22
#include "../dmdism/disassembly.h"
3-
#include "../debug_server/debug_server.h"
43
#include "../crash_guard/crash_guard.h"
54

65
#include <fstream>
@@ -78,25 +77,6 @@ class ext_vector : std::vector<T>
7877
}
7978
};
8079

81-
#ifdef _WIN32
82-
opcode_handler _generate_number_op_localm_localn_store_localx(unsigned char op, int localm, int localn, int localx)
83-
{
84-
unsigned char* func = (unsigned char*)VirtualAlloc(NULL, 64, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
85-
if (!func)
86-
{
87-
return nullptr;
88-
}
89-
std::memcpy(func, _number_op_localm_localn_store_localx, 26);
90-
func[16] = op;
91-
func[13] = 4 + 8 * localm;
92-
func[18] = 4 + 8 * localn;
93-
func[23] = 4 + 8 * localx;
94-
DWORD old_prot;
95-
VirtualProtect(func, 64, PAGE_EXECUTE_READ, &old_prot);
96-
return (opcode_handler)func;
97-
}
98-
#endif
99-
10080
extern "C" EXPORT void add_subvars_of_locals(ExecutionContext* ctx)
10181
{
10282
Value a = ctx->local_variables[0];
@@ -123,109 +103,6 @@ void init_testing()
123103
{
124104
o << i.offset() << "\t\t\t" << i.bytes_str() << "\t\t\t" << i.opcode().mnemonic() << " " << i.comment() << "\n";
125105
}
126-
//Value a(5.0f);
127-
//Value b = a + 5.0f;
128-
//b += 1.0f;
129-
//Core::Alert(std::to_string(b));
130-
//ManagedValue a = Value::World().get("name");
131-
//dump_full_obj_mem_usage();
132-
//Core::Alert("end func");
133-
//Core::global_direct_set("internal_tick_usage", "AYYLMAO");
134-
//Core::Alert(Core::global_direct_get("internal_tick_usage"));
135-
//Core::Alert(Core::GetStringFromId(0x86));
136-
//Core::get_proc("/proc/get_string_by_id").hook(test_invoke);
137-
//Core::Alert(Core::get_proc("/client/verb/hidden").proc_table_entry->procFlags);
138-
//Core::Alert(Core::get_proc("/client/verb/nothidden").proc_table_entry->procFlags);
139-
//Core::get_proc("/client/verb/toggle_hidden_verb").hook(toggle_verb_hidden);
140-
//Core::get_proc("/client/verb/hidden").proc_table_entry->procFlags = 4;
141-
//initialize_profiler_access();
142-
//enable_crash_guard();
143-
//optimizer_initialize();
144-
//Core::Alert(Core::stringify({ 0x0C, 0x00 }));
145-
//Core::Proc p = "/proc/pickdism";
146-
//std::ofstream o("out.txt");
147-
//for (Instruction& i : p.disassemble())
148-
//{
149-
// o << i.offset() << "\t\t\t" << i.bytes_str() << "\t\t\t" << i.opcode().mnemonic() << "\n";
150-
//}
151-
/*Core::Proc p = "/proc/bench_intrinsic_add";
152-
Disassembly d = p.disassemble();
153-
Core::Proc intrinsic_add = "/proc/__intrinsic_add_locals";
154-
std::vector<std::uint32_t>* new_bytecode = new std::vector<std::uint32_t>;
155-
for (int i = 0; i < d.size(); i++)
156-
{
157-
if (d.at(i) == CALLGLOB && d.at(i).bytes().at(2) == intrinsic_add.id)
158-
{
159-
Instruction first_arg = d.at(i - 2);
160-
Instruction second_arg = d.at(i - 1);
161-
Instruction destination = d.at(i + 1);
162-
new_bytecode->resize(new_bytecode->size() - 6);
163-
int intrinsic_op = Core::register_opcode("INTRINSIC_ADD_NUMBERS_"+std::to_string(rand()), _generate_number_op_localm_localn_store_localx(ADD, first_arg.bytes().at(2), second_arg.bytes().at(2), destination.bytes().at(2)));
164-
new_bytecode->push_back(intrinsic_op);
165-
i += 1;
166-
}
167-
else
168-
{
169-
for (unsigned int& byte : d.at(i).bytes())
170-
{
171-
new_bytecode->push_back(byte);
172-
}
173-
}
174-
}
175-
for (int i = 0; i < 10; i++)
176-
{
177-
new_bytecode->push_back(0x00);
178-
}
179-
p.set_bytecode(new_bytecode);
180-
std::ofstream o("out.txt");
181-
for (Instruction& i : Core::get_proc("/proc/bench_dm_add").disassemble())
182-
{
183-
o << i.offset() << "\t\t\t" << i.bytes_str() << "\t\t\t" << i.opcode().mnemonic() << "\n";
184-
}*//*
185-
bool find_unknowns = false;
186-
if (find_unknowns)
187-
{
188-
std::ofstream log("unknown_opcodes.txt");
189-
for (Core::Proc& p : Core::get_all_procs())
190-
{
191-
if (!p.name.empty() && p.name.back() == ')')
192-
{
193-
continue;
194-
}
195-
Disassembly d = p.disassemble();
196-
for (Instruction& i : d)
197-
{
198-
if (i == UNK)
199-
{
200-
log << "Unknown instruction in " + p.name + "\n";
201-
break;
202-
}
203-
}
204-
}
205-
log.close();
206-
}*/
207-
208-
//debugger_connect();
209-
//Core::get_proc("/datum/explosion/New").extended_profile();
210-
//Core::get_proc("/client/verb/test_reentry").extended_profile();
211-
//Core::get_proc("/client/verb/test_extended_profiling").extended_profile();
212-
//extended_profiling_procs[.id] = true;
213-
//Core::get_proc("/proc/cheap_hypotenuse_hook").hook(cheap_hypotenuse);
214-
//Core::get_proc("/proc/measure_get_variable").hook(measure_get_variable);
215-
//Core::get_proc("/proc/laugh").hook(show_profiles);
216-
217-
/*int hypotenuse_opcode = Core::register_opcode("CHEAP_HYPOTENUSE", cheap_hypotenuse_opcode);
218-
Core::Proc& hypotenuse_bench = Core::get_proc("/proc/bench_cheap_hypotenuse_native");
219-
Disassembly dis = hypotenuse_bench.disassemble();
220-
for (Instruction& instr : dis)
221-
{
222-
if (instr == Bytecode::CALLGLOB)
223-
{
224-
instr = Instruction(hypotenuse_opcode);
225-
break;
226-
}
227-
}
228-
hypotenuse_bench.assemble(dis);*/
229106
}
230107

231108
void run_tests()

0 commit comments

Comments
 (0)