Skip to content

Commit

Permalink
Big update
Browse files Browse the repository at this point in the history
1.) Added a load of new hashes in src/util/translations/general.cr
2.) Tweaked some of the code to be little nicer overall
3.) Normalized a few of the file/directory names
4.) Updated the default localize.json file to be up to date with v1.31.3 (MWIII)
  • Loading branch information
Nico-Posada committed Mar 20, 2024
1 parent 5069502 commit 0e5ed55
Show file tree
Hide file tree
Showing 10 changed files with 4,760 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bin/
src/util/c-src/fnv64.o
src/util/bindings/fnv64.o
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
# CoD Lua Dehasher
This is a program that's able to take Call of Duty's decompiled Lua files, and dehash about 99% of their file names while also dehashing many strings and function names.
This is a program that's able to take Call of Duty's decompiled lua files, and dehash about 99% of their file names while also dehashing many strings and function names.

**BIG OVERHAUL UPDATE**:<br>
I updated this project to use [Crystal](https://crystal-lang.org) instead of Ruby. If you look at the code between the old version (still in the `legacy` folder) and the new version, you'll notice that the code looks somewhat similar. That's because Crystal is, in simple terms, just a compiled Ruby. This makes the script run much faster along with the code being a lot safer now! I also changed how the localize JSON should be structed along with a few minor bug-fixes.

# Requirements
To be able to run the program you will not need to install anything. To compile the program, you need to install `Crystal` ([Windows Install](https://crystal-lang.org/install/on_windows/)) and `GCC` (Windows install can be found [here](https://github.com/niXman/mingw-builds-binaries/releases) with release win32-seh-msvcrt).
To be able to run the program you will not need to install anything. To compile the program, you need to install `Crystal` ([Windows Install](https://crystal-lang.org/install/on_windows/)) and `GCC` (Windows installation instructions [here](https://www.msys2.org)).

# Before Running
You must decompile your Lua files using JariK's Lua decompiler found [here](https://github.com/JariKCoding/CoDLuaDecompiler). There is a slight flaw in the code where hashes are truncated to 60 bits when they shouldn't be truncated at all.
You must decompile your lua files using JariK's lua decompiler found [here](https://github.com/JariKCoding/CoDLuaDecompiler). There is a slight flaw in the code where hashes are truncated to 60 bits when they shouldn't be truncated at all.

I have recently made a fork with the required fixes found [here](https://github.com/Nico-Posada/CoDLuaDecompiler).

# Usage
In the command line, type the following:
In the command line, type the following command:
`./lua_dehasher.exe <path>`
where `path` is the path to your directory holding all of your Lua files.
where `path` is the path to your directory holding all of your lua files.
<br>**OR**<br>
Drag and drop your folder of Lua files onto the exe file and it'll begin execution.
Drag and drop your folder of lua files onto the exe file and it'll begin execution.

You'll also need a localize.json file (a default one can be found in the `localize` directory in this repository). When running the program, make sure to have this localize.json file in the same directory as the executable. Although the json isn't required to actually run the program, it still helps to make the final Lua file outputs much cleaner.
You can optionally include a `localize.json` file (a default one can be found in the `localize` directory in this repository). When running the program, make sure to have this json file in the same directory as the executable. Although the json isn't required to actually run the program, it still helps to make the final lua file outputs much cleaner.

# What to Expect
When the dehasher finishes, you'll notice a new directory named `Parsed` appear in the original directory you passed to the program. This will contain 2 subdirectories named `Hashed` and `Dehashed`. As the name suggests, Hashed contains all the files with names that could not be dehashed, and Dehashed contains all the files with names that were successfully dehashed. Upon opening any of the Lua files, you'll notice many strings marked with a `--[[DH]]` which means that those were hashed strings that the program dehashed.
When the dehasher finishes, you'll notice a new directory named `Parsed` appear in the original directory you passed to the program. This will contain 2 subdirectories named `Hashed` and `Dehashed`. As the name suggests, Hashed contains all the files with names that could not be dehashed, and Dehashed contains all the files with names that were successfully dehashed. Upon opening any of the lua files, you'll notice many strings marked with a `--[[DH]]` which means that those were hashed strings that the program dehashed.

# Compiling
I have provided a `build.bat` file. After installing the requirements, run `build.bat`, and go to the `bin` directory. The executable will be there.

# Contributing
If you would like to contribute in any way, even if it is just adding new hashes to the list of translations, I will gladly accept any help. Fork the repository, make your changes, and then make a pull request with those changes.
4 changes: 2 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo off
mkdir bin 2> NUL
gcc -m64 -Wall -O3 -march=native -c .\src\util\C-src\fnv64.c -o .\src\util\C-src\fnv64.o
crystal build -o .\bin\lua_dehasher.exe .\src\lua_dehasher.cr --release --no-debug
gcc -m64 -Wall -O3 -march=native -c .\src\util\bindings\fnv64.c -o .\src\util\bindings\fnv64.o
crystal build -o .\bin\lua_dehasher.exe .\src\lua_dehasher.cr --release --no-debug --stats --progress --time
16 changes: 8 additions & 8 deletions src/lua_dehasher.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% if flag?(:win32) %}
require "./util/fnv64.cr"
require "./util/cod-lua-functions.cr"
require "./util/dehashing-util.cr"
require "./util/translations/functions.cr"
require "./util/dehashing_util.cr"

def main() : Int32
if ARGV.size != 1
Expand All @@ -16,10 +16,10 @@ def main() : Int32
end

# initialization
cod : CodFunctions = CodFunctions.new
# cod : CoDFunctions = CoDFunctions.new

# change a path like 'C:\path\to\somwhere\' to 'C:/path/to/somwhere'
fixed_dirname : String = dir.tr("\\", "/").sub(/\/$/,"")
fixed_dirname : String = dir.tr("\\", "/").sub(/\/$/, "")

# grab all lua files that need fixing and make sure there are any at all
files : Array(String) = Dir.glob("#{fixed_dirname}/*.dec.lua")
Expand Down Expand Up @@ -49,7 +49,7 @@ def main() : Int32
filenames[hash] = fixed_filename unless filenames.has_key?(hash)
end

puts "Number of possible Lua file names => #{filenames.size}"
puts "Number of possible lua file names => #{filenames.size}"

# search for localize json and parse
dehash : Dehasher = Dehasher.new
Expand Down Expand Up @@ -78,8 +78,8 @@ def main() : Int32
files.each_with_index do |file, i|
# fix all function names and strings
lua_file = File.read(file)
lua_file = dehash.fix_functions(lua_file, cod.funcs)
lua_file = dehash.fix_strings(lua_file) if localize_set_up
lua_file = dehash.fix_functions(lua_file)
lua_file = dehash.fix_general(lua_file) if localize_set_up

# using the hash of the filename, check to see if we were able to find the plaintext filename anywhere
hashed_filename : String = File.basename(file, ".dec.lua")
Expand Down Expand Up @@ -108,7 +108,7 @@ def main() : Int32
end
end

puts "\n\nFiles dehashed => #{dehashed_files}", "Files unable to dehash => #{hashed_files}", "\nDone!"
puts "\n\nFilenames fixed => #{dehashed_files}", "Filenames unable to fix => #{hashed_files}", "\nDone!"
return 0
end

Expand Down
File renamed without changes.
21 changes: 16 additions & 5 deletions src/util/dehashing-util.cr → src/util/dehashing_util.cr
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
require "json"
require "./cod-lua-functions.cr"
require "./translations/functions.cr"
require "./translations/general.cr"
require "./fnv64.cr"

class Dehasher
@localize : Hash(UInt64, String) = {} of UInt64 => String
@@functions : CoDFunctions = CoDFunctions.new
@@general : CoDGeneralHashes = CoDGeneralHashes.new

def initialize
end
Expand All @@ -20,17 +23,25 @@ class Dehasher
return true
end

def fix_functions(lua_file : String, funcs : Hash(UInt64, String)) : String
def fix_functions(lua_file : String) : String
lua_file.gsub(/(\w+?)\[0x([A-F\d]+)\]\(/){
hash : UInt64 = $2.to_u64(16)
funcs.has_key?(hash) ? "#{$1}[ \"#{funcs[hash]}\" --[[DH]] ](" : "#{$1}[ 0x#{$2} ]("
@@functions.funcs.has_key?(hash) ? "#{$1}[ \"#{@@functions.funcs[hash]}\" --[[DH]] ](" : "#{$1}[ 0x#{$2} ]("
}
end

def fix_strings(lua_file : String) : String
def fix_general(lua_file : String) : String
lua_file.gsub(/0x([A-F\d]+)/){
hash : UInt64 = $1.to_u64(16)
@localize.has_key?(hash) ? "\"#{@localize[hash]}\" --[[DH]]" : $~[0]
result : String = $~[0]

if @localize.has_key?(hash)
result = "\"#{@localize[hash]}\" --[[DH]]"
elsif @@general.hashes.has_key?(hash)
result = "\"#{@@general.hashes[hash]}\" --[[DH]]"
end

result
}
end
end
2 changes: 1 addition & 1 deletion src/util/fnv64.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@[Link(ldflags: "#{__DIR__}/c-src/fnv64.o")]
@[Link(ldflags: "#{__DIR__}/bindings/fnv64.o")]
lib LibFnv64
fun fnv64(string : UInt8*) : UInt64
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class CodFunctions
# list of function names and their hashes dumped from the MW19 pdb
class CoDFunctions
@funcs : Hash(UInt64, String) = {} of UInt64 => String
def initialize
@funcs = {
Expand Down
Loading

0 comments on commit 0e5ed55

Please sign in to comment.