From 4835715a06101d612f318811ab33cf148e9d66be Mon Sep 17 00:00:00 2001 From: Hunter Kvalevog Date: Mon, 4 Mar 2019 21:42:42 -0600 Subject: [PATCH] Fix Schema_Reload() --- src/hacks/Misc.cpp | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/hacks/Misc.cpp b/src/hacks/Misc.cpp index f161c4da..6a2d1877 100644 --- a/src/hacks/Misc.cpp +++ b/src/hacks/Misc.cpp @@ -389,45 +389,37 @@ void DrawText() } #endif -/* + void Schema_Reload() { - logging::Info("Custom schema loading is not supported right now."); + static auto GetItemSchema = reinterpret_cast(gSignatures.GetClientSignature("55 89 E5 57 56 53 83 EC ? 8B 1D ? ? ? ? 85 DB 89 D8")); - static uintptr_t InitSchema_s = gSignatures.GetClientSignature("55 89 E5 57 56 53 83 EC ? 8B 5D ? 8B 7D ? 8B 03 89 1C 24 FF 50 ? C7 " - "04 24 ? ? ? ?"); - typedef bool (*InitSchema_t)(void *, CUtlBuffer &, int); - static InitSchema_t InitSchema = (InitSchema_t) InitSchema_s; - static uintptr_t GetItemSchema_s = gSignatures.GetClientSignature("55 89 E5 83 EC ? E8 ? ? ? ? C9 83 C0 ? C3 55 89 E5 8B 45 ?"); - typedef void *(*GetItemSchema_t)(void); - static GetItemSchema_t GetItemSchema = (GetItemSchema_t) GetItemSchema_s; //(*(uintptr_t*)GetItemSchema_s +GetItemSchema_s + 4); + static auto BInitTextBuffer = reinterpret_cast(gSignatures.GetClientSignature("55 89 E5 57 56 53 8D 9D ? ? ? ? 81 EC ? ? ? ? 8B 7D ? 89 1C 24 ")); + void* schema = GetItemSchema() + 0x4; - logging::Info("0x%08x 0x%08x", InitSchema, GetItemSchema); - void *itemschema = (void *) ((unsigned) GetItemSchema() + 4); - void *data; - char *path = strfmt("/opt/cathook/data/items_game.txt").get(); - FILE *file = fopen(path, "r"); - delete[] path; - fseek(file, 0L, SEEK_END); - char buffer[5 * 1000 * 1000]; - size_t len = ftell(file); - rewind(file); - buffer[len + 1] = 0; - fread(&buffer, sizeof(char), len, file); - CUtlBuffer buf(&buffer, 5 * 1000 * 1000, 9); + FILE *file = fopen("/opt/cathook/data/items_game.txt", "r"); if (ferror(file) != 0) { logging::Info("Error loading file"); fclose(file); return; } + + // CUtlBuffer + char* text_buffer = new char[1000 * 1000 * 5]; + size_t buffer_size = fread(text_buffer, sizeof(char), 1000 * 1000 * 5, file); + + CUtlBuffer buf(text_buffer, buffer_size, 9); + fclose(file); - logging::Info("0x%08x 0x%08x", InitSchema, GetItemSchema); - bool ret = InitSchema(GetItemSchema(), buf, 133769); + logging::Info("Loading item schema..."); + bool ret = BInitTextBuffer(schema, buf, 0); logging::Info("Loading %s", ret ? "Successful" : "Unsuccessful"); + + delete[] text_buffer; } CatCommand schema("schema", "Load custom schema", Schema_Reload); -*/ + CatCommand name("name_set", "Immediate name change", [](const CCommand &args) { if (args.ArgC() < 2) {